BonyadCode.Paginator.AspNetCore
1.0.4
There is a newer version of this package available.
See the version list below for details.
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" />
<PackageReference Include="BonyadCode.Paginator.AspNetCore" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=BonyadCode.Paginator.AspNetCore&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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) andIEnumerable
. - 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
andMicrosoft.EntityFrameworkCore
.
🤝 Contributing
Contributions, suggestions, and PRs are welcome! GitHub →
📄 License
Apache 2.0 — see the LICENSE file.
📦 Links
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
- Microsoft.EntityFrameworkCore (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.