Pagination
Read a page at a time with the page size and page number.
What Is Pagination?#
Pagination in short means dividing the results into chunks of a determinate size called Pages.
Then pulling only one of those Pages at time.
Subsequently, pulling the next or the previous page as needed.
For example on a screen that displays orders. And the total number of orders are 1 million but you only want to display 10 at a time.
Pagination And Query#
Paging or Pagination can be used to build your Query instance.
To learn about how to craft the Query instance go to the Filtering section of the documentation.
You can also check out the Query Syntax section of the documentation.
Using Pagination#
Pagination is disabled by default.
To enable paging you must configure it by calling these methods in your Query instance:
-
PageSize: takes an integer that specifies the number of records to fetch per page.
-
PageNumber: takes an integer that specifies which page to return. The first page is 1.
-
ReturnTotalCount: takes a boolean.
If true the properties PageCount and RecordCount of the Query instance will be populated after the query is executed.
The default value is false.
The below code sample shows how to retrieve the second page of the results with a page size of 25 from the Orders table.
Fluent Syntax#
// create an instance of the Repository Container// remember this can be a singleton if you// declare it early on and reuse it for the// lifetime of your applicationvar repo = new RepositoryContainer();// create an instance of Query and// specify the entity's property container// apply paginationvar query = new Query<OrderProperty>() .BeginPagination() .PageSize(25) .PageNumber(2) .ReturnTotalCount(true) .EndPagination();// pass the query to one of the repository methods// in this case the ToList on the Order repositoryvar result = repo.AppDb.Sales.Order.ToList(query);// get the total number of pages// also get the total number of records// because we set ReturnTotalCount = true// these fields will be populatedvar totalPages = query.PageCount;var totalRecords = query.RecordCount;Builder Syntax#
// create an instance of the Repository Container// remember this can be a singleton if you// declare it early on and reuse it for the// lifetime of your applicationvar repo = new RepositoryContainer();// create an instance of Query and// specify the entity's property container// apply paginationvar query = new Query<OrderProperty>() .Builder(builder => { builder .Pagination((pagination) => { pagination .PageSize(25) .PageNumber(2) .ReturnTotalCount(true); }); });// pass the query to one of the repository methods// in this case the ToList on the Order repositoryvar result = repo.AppDb.Sales.Order.ToList(query);// get the total number of pages// also get the total number of records// because we set ReturnTotalCount = true// these fields will be populatedvar totalPages = query.PageCount;var totalRecords = query.RecordCount;