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" />
                    
Directory.Packages.props
<PackageReference Include="Philiprehberger.Pagination" />
                    
Project file
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
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=Philiprehberger.Pagination&version=0.1.9
                    
Install as a Cake Tool

Philiprehberger.Pagination

CI NuGet Last updated

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.Run internally. If you are using EF Core, prefer calling CountAsync and ToListAsync directly 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:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

Product 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.

Version Downloads Last Updated
0.1.9 118 4/1/2026
0.1.8 111 3/27/2026
0.1.7 104 3/25/2026
0.1.6 105 3/25/2026
0.1.5 107 3/23/2026
0.1.4 113 3/17/2026
0.1.3 113 3/16/2026
0.1.2 104 3/16/2026
0.1.1 111 3/16/2026
0.1.0 112 3/16/2026