Skip to content

The search box knows all the secrets -- try it!

Polecat is part of the Critter Stack ecosystem.

JasperFx Logo JasperFx provides formal support for Polecat and other Critter Stack libraries. Please check our Support Plans for more details.

Paging

Polecat provides built-in pagination support via the IPagedList<T> interface.

ToPagedListAsync

The simplest way to paginate results:

cs
var pagedList = await session.Query<User>()
    .OrderBy(x => x.LastName)
    .ToPagedListAsync(pageNumber: 1, pageSize: 20);

TIP

Page numbers are 1-based, not 0-based.

IPagedList Properties

The returned IPagedList<T> includes:

PropertyDescription
TotalItemCountTotal items across all pages
PageCountTotal number of pages
PageNumberCurrent page number (1-based)
PageSizeItems per page
HasPreviousPageWhether a previous page exists
HasNextPageWhether a next page exists
IsFirstPageWhether this is the first page
IsLastPageWhether this is the last page
FirstItemOnPage1-based index of first item on this page
LastItemOnPage1-based index of last item on this page

How It Works

ToPagedListAsync executes two queries:

  1. A COUNT(*) query for the total number of matching documents
  2. A SELECT with OFFSET/FETCH for the current page's data

Both queries run against the same filter criteria.

Manual Paging

You can also page manually with Skip and Take:

cs
var page2 = await session.Query<User>()
    .OrderBy(x => x.LastName)
    .Skip(20)
    .Take(10)
    .ToListAsync();

WARNING

Always use OrderBy with paging to ensure consistent results across pages.

Released under the MIT License.