BonyadCode.Paginator.AspNetCore 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package BonyadCode.Paginator.AspNetCore --version 1.0.4
                    
NuGet\Install-Package BonyadCode.Paginator.AspNetCore -Version 1.0.4
                    
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="BonyadCode.Paginator.AspNetCore" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BonyadCode.Paginator.AspNetCore" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="BonyadCode.Paginator.AspNetCore" />
                    
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 BonyadCode.Paginator.AspNetCore --version 1.0.4
                    
#r "nuget: BonyadCode.Paginator.AspNetCore, 1.0.4"
                    
#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 BonyadCode.Paginator.AspNetCore@1.0.4
                    
#: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=BonyadCode.Paginator.AspNetCore&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=BonyadCode.Paginator.AspNetCore&version=1.0.4
                    
Install as a Cake Tool

BonyadCode.Paginator.AspNetCore

A minimal yet powerful pagination utility for .NET developers. Enables easy paging over IQueryable<T> or IEnumerable<T> sources with optional dynamic ordering via expressions or property names — ideal for APIs, dashboards, and any list-heavy UIs.


✨ Features

  • Unified Paging API: Works seamlessly with both IQueryable (e.g., EF Core) and IEnumerable.
  • Dynamic Ordering: Sort by expression or string field name (e.g., "CreatedAt").
  • Smart Caching: Expression caching ensures optimal performance for repeated queries.
  • Async + Sync Support: Optimized methods for both LINQ-to-Objects and LINQ-to-Entities.
  • Safe Defaults: Sensible defaults for page size, number, and ordering.

📦 Installation

dotnet add package BonyadCode.Paginator.AspNetCore

🚀 Quick Examples

✅ Paginate an EF Core Query

var request = new PagedRequest
{
    PageNumber = 2,
    PageSize = 10,
    OrderBy = "CreatedAt",
    AscendingOrder = true
};

var result = await dbContext.Users
    .Where(u => u.IsActive)
    .ToPagedResponseAsync(request, cancellationToken: cancellationToken);

or

var request = new PagedRequest
{
    PageNumber = 2,
    PageSize = 10,
    OrderBy = nameof(Request.CreatedAt),
    AscendingOrder = true
};

var result = await dbContext.Users
    .Where(u => u.IsActive)
    .ToPagedResponseAsync(request, cancellationToken: cancellationToken);

Result JSON:

{
  "pageNumber": 2,
  "pageSize": 10,
  "pageCount": 5,
  "itemCount": 42,
  "hasPreviousPage": true,
  "hasNextPage": true,
  "items": [ /* paginated users */ ]
}

✅ Paginate an In-Memory List

var users = new List<User> { /* ... */ };

var request = new PagedRequest
{
    PageNumber = 1,
    PageSize = 5,
    OrderBy = "Username",
    AscendingOrder = false
};

var result = users.ToPagedResponse(request);

📘 API Overview

📟 PagedRequest

Property Type Description Default
PageNumber uint? Page to retrieve 1
PageSize uint? Number of items per page 20
OrderBy string? Field/property to sort by "Id"
AscendingOrder bool? Whether to sort ascending false

📦 PageBuilder<T>

Property Type Description
Items IList<T> The data for the current page
PageNumber uint Current page number
PageSize uint Items per page
PageCount uint Total number of pages
ItemCount uint Total number of items
HasPreviousPage bool Whether a previous page exists
HasNextPage bool Whether a next page exists

🧐 Advanced Usage

📌 Paginate with Expression

Expression<Func<User, object>> orderByExpr = x => x.Email;

var result = await dbContext.Users
    .ToPagedResponseAsync(request, orderByExpr, cancellationToken);

🔄 Runtime Property Sorting

var result = await dbContext.Products
    .ToPagedResponseAsync(new PagedRequest
    {
        OrderBy = "Price",
        AscendingOrder = true
    });

Field name must match a public property of the type (case-insensitive).


🔧 Internals & Performance

  • Uses ConcurrentDictionary<Type, Dictionary<string, Expression>> for dynamic sorting — field expressions are cached per type for reuse.
  • Null-safe and validated defaults — throws if PageSize == 0.
  • CancellationToken respected on all async methods.
  • Compatible with both System.Linq and Microsoft.EntityFrameworkCore.

🤝 Contributing

Contributions, suggestions, and PRs are welcome! GitHub →

📄 License

Apache 2.0 — see the LICENSE file.

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.

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
1.0.6 119 6/8/2025
1.0.5 155 6/4/2025
1.0.4 158 5/25/2025
1.0.3 162 5/25/2025
1.0.2 78 5/24/2025
1.0.1 75 5/24/2025
1.0.0 74 5/24/2025