Philiprehberger.Pagination
0.1.9
dotnet add package Philiprehberger.Pagination --version 0.1.9
NuGet\Install-Package Philiprehberger.Pagination -Version 0.1.9
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Philiprehberger.Pagination" Version="0.1.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Philiprehberger.Pagination" Version="0.1.9" />
<PackageReference Include="Philiprehberger.Pagination" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Philiprehberger.Pagination --version 0.1.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Philiprehberger.Pagination, 0.1.9"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Philiprehberger.Pagination@0.1.9
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Philiprehberger.Pagination&version=0.1.9
#tool nuget:?package=Philiprehberger.Pagination&version=0.1.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Philiprehberger.Pagination
Standardized pagination primitives — PagedResult, cursor-based pagination, and IQueryable extensions.
Installation
dotnet add package Philiprehberger.Pagination
Usage
Offset-Based Pagination
using Philiprehberger.Pagination;
// Paginate a queryable source
var result = dbContext.Products
.OrderBy(p => p.Name)
.ToPagedResult(page: 1, pageSize: 20);
Console.WriteLine($"Page {result.Page} of {result.TotalPages}");
Console.WriteLine($"Showing {result.Items.Count} of {result.TotalCount} items");
if (result.HasNextPage)
Console.WriteLine("More pages available");
Cursor-Based Pagination
using Philiprehberger.Pagination;
var cursorResult = new CursorPagedResult<Product>(
Items: products,
Cursor: lastProduct?.Id.ToString(),
HasMore: products.Count == pageSize
);
if (cursorResult.HasMore)
Console.WriteLine($"Next cursor: {cursorResult.Cursor}");
Pagination Request Validation
using Philiprehberger.Pagination;
var request = new PaginationRequest(Page: 1, PageSize: 50);
request.Validate(); // throws if invalid (page < 1, pageSize < 1 or > 100)
// Custom max page size
request.Validate(maxPageSize: 200);
Async Pagination
using Philiprehberger.Pagination;
var result = await queryable.ToPagedResultAsync(page: 2, pageSize: 10, cancellationToken);
Note: The async extension uses
Task.Runinternally. If you are using EF Core, prefer callingCountAsyncandToListAsyncdirectly for true async database operations.
API
PagedResult<T>
| Member | Type | Description |
|---|---|---|
Items |
IReadOnlyList<T> |
Items on the current page |
TotalCount |
int |
Total number of items across all pages |
Page |
int |
Current page number (1-based) |
PageSize |
int |
Maximum items per page |
TotalPages |
int |
Computed total number of pages |
HasNextPage |
bool |
Whether a next page exists |
HasPreviousPage |
bool |
Whether a previous page exists |
Empty<T>() |
PagedResult<T> |
Creates an empty result |
CursorPagedResult<T>
| Member | Type | Description |
|---|---|---|
Items |
IReadOnlyList<T> |
Items in the current page |
Cursor |
string? |
Cursor for the next page, or null |
HasMore |
bool |
Whether more items are available |
PaginationRequest
| Member | Type | Description |
|---|---|---|
Page |
int |
Page number (default: 1) |
PageSize |
int |
Items per page (default: 20) |
Validate(maxPageSize) |
void |
Validates the request, throws on invalid values |
QueryableExtensions
| Method | Returns | Description |
|---|---|---|
ToPagedResult<T>(page, pageSize) |
PagedResult<T> |
Paginates a queryable source |
ToPagedResultAsync<T>(page, pageSize, ct) |
Task<PagedResult<T>> |
Async pagination via Task.Run |
Development
dotnet build src/Philiprehberger.Pagination.csproj --configuration Release
Support
If you find this project useful:
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.