DynamicWhere.ex
DynamicWhere.exv3.4.0·docs

.Page<T>(page)

Paginates the query using a PageBy descriptor. Internally this skips (PageNumber - 1) * PageSize records and takes PageSize.

Signature

public static IQueryable<T> Page<T>(this IQueryable<T> query, PageBy page)
    where T : class
ParameterTypeDescription
pagePageByPage number and size

Validations

  • PageNumber must be > 0 — error code InvalidPageNumber.
  • PageSize must be > 0 — error code InvalidPageSize.

Returns

IQueryable<T> — paged query.

Example

var paged = dbContext.Products.Page(new PageBy
{
    PageNumber = 1,
    PageSize   = 25
});
{
  "pageNumber": 1,
  "pageSize": 25
}
A page past the last row is an empty page (3.3.0)
The offset is worked out in 64 bits and held to int.MaxValue, here and in the three summary methods. In 32 bits the product wrapped for a large enough page number: a negative offset is an error on SQL Server and PostgreSQL, so the request became a five-hundred, and the first page again on SQLite and in memory, so a page far past the last row returned rows. A page past the last row is now an empty page however far past it is, as it always was for a page number that did not wrap. The policy layer caps PageSize and never PageNumber, so a guarded query took the same path.
Warning
Page does not order. Skipping rows of an unordered query lets the database return them in any order it likes, so two pages can repeat or miss a row. Always send an Orders list with a page.

See also