ISqlQueryBuilder.Page(int page, int count) Method
.NET Standard 2.x
Specifies that the SQL SELECT statement of the current object only returns the data on the specified page of the paginated result set.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlBuilder Page(int page, int count);
Parameters
page
System.Int32
The zero-based number of the page that you want to get the result set.
count
System.Int32
The number of rows for each page.
Returns
Returns an ISqlBuilder
object which represents the current object.
Examples
The following code example demonstrates how to use the Page(int page, int count) method to paginate the data and gets the data of the second page.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlQueryBuilderExamples
{
public class PageExample
{
private SchoolContext _context;
public PageExample(SchoolContext dataContext)
{
// Sets Data Context.
_context = dataContext;
}
public void Example()
{
// Declares SqlQueryBuilder.
var sqlbuilder = new SqlQueryBuilder();
// Retrieves all the values from the "Course" table.
sqlbuilder.Select("*")
.From("Course");
// Puts 5 records in every page, and gets data in the 2nd page
sqlbuilder.Page(1,5);
// Converts to raw SQL for the database corresponding to the data context.
string sql = sqlbuilder.ToSqlString(_context);
Console.WriteLine(sql);
/*This code produces the following output:
SELECT
TOP(5) *
FROM(SELECT
*,
ROW_NUMBER() OVER(
ORDER BY
(SELECT
1)) AS __P_P_H_S__ROW_NUMBER__P_P_H_E__
FROM [Course]) AS __TABLE_NAME__
WHERE __P_P_H_S__ROW_NUMBER__P_P_H_E__ > 5
*/
}
}
}
Applies to
.NET Standard
2.x