Naravel.Pagination.EntityFrameworkCore
0.2.0
dotnet add package Naravel.Pagination.EntityFrameworkCore --version 0.2.0
NuGet\Install-Package Naravel.Pagination.EntityFrameworkCore -Version 0.2.0
<PackageReference Include="Naravel.Pagination.EntityFrameworkCore" Version="0.2.0" />
<PackageVersion Include="Naravel.Pagination.EntityFrameworkCore" Version="0.2.0" />
<PackageReference Include="Naravel.Pagination.EntityFrameworkCore" />
paket add Naravel.Pagination.EntityFrameworkCore --version 0.2.0
#r "nuget: Naravel.Pagination.EntityFrameworkCore, 0.2.0"
#:package Naravel.Pagination.EntityFrameworkCore@0.2.0
#addin nuget:?package=Naravel.Pagination.EntityFrameworkCore&version=0.2.0
#tool nuget:?package=Naravel.Pagination.EntityFrameworkCore&version=0.2.0
Naravel.Pagination.EntityFrameworkCore
PaginateAsync, SimplePaginateAsync and CursorPaginateAsync for EF Core queries, returning Naravel.Pagination results. Keyset (cursor) paging applies both the order and the filter from one key declaration.
| Fact | Detail |
|---|---|
| Install | dotnet add package Naravel.Pagination.EntityFrameworkCore |
| Targets | .NET 10 |
| Needs | Naravel.Pagination and Microsoft.EntityFrameworkCore, which NuGet installs with it, and the EF Core provider that your own DbContext uses |
What you get
- Three kinds of page.
PaginateAsyncreturns aPaginated<T>with a total,SimplePaginateAsyncaSimplePaginated<T>with no count, andCursorPaginateAsyncaCursorPaginated<T>read by keyset. - Laravel's page shape. A page serializes as
data,linksandmeta, andWithPathsets where the links point. - One key declaration.
k.By(p => p.CreatedAt, descending: true).Then(p => p.Id)gives the cursor query its order and its filter. - Back and forth.
NextCursorandPreviousCursorwalk a feed in both directions, and an exact fit does not invent a next page.
Quick start
using Naravel.Pagination; // PaginateAsync, SimplePaginateAsync and CursorPaginateAsync extend IQueryable<T>
// AppDb and its Posts set are your own DbContext and entity.
app.MapGet("/posts", async (AppDb db, int? page, CancellationToken ct) =>
{
var posts = await db.Posts.OrderBy(p => p.Id).PaginateAsync(page ?? 1, 15, ct);
return Results.Ok(posts.WithPath("/posts")); // Results is ASP.NET Core; the page serializes as data, links and meta
});
The offset forms need an ordered query: one without OrderBy throws InvalidOperationException. A page below 1 is read as page 1, a page size below 1 throws ArgumentOutOfRangeException, and a size above PaginationOptions.MaxPerPage (100 unless you pass your own options) is reduced to it. SimplePaginateAsync takes the same arguments and runs no count.
For a feed, declare keys instead of ordering the query:
app.MapGet("/feed", async (AppDb db, string? cursor, CancellationToken ct) =>
{
try
{
var feed = await db.Posts.CursorPaginateAsync(k => k.By(p => p.CreatedAt, descending: true).Then(p => p.Id), 15, cursor, ct);
return Results.Ok(feed.WithPath("/feed"));
}
catch (InvalidCursorException)
{
return Results.BadRequest("invalid cursor");
}
});
The keys together must be unique, so end with the primary key: if two rows share every key, one of them can be skipped or repeated, and the helper cannot check that. A cursor is a position, not a secret and not a permission. It is not signed, so a client can edit it, and one that cannot be read throws InvalidCursorException.
Related packages
| Package | Adds |
|---|---|
Naravel.Pagination |
The page types and options that this package fills from EF Core queries |
Learn more
- Pagination: English guide
- Changelog · Source and issues · MIT license
Part of Naravel: Laravel's names, .NET's type system. All Naravel packages share one version.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Microsoft.EntityFrameworkCore (>= 10.0.14)
- Naravel.Pagination (>= 0.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Release notes: https://github.com/km-arc/Naravel/releases/tag/v0.2.0 - full history: https://github.com/km-arc/Naravel/blob/main/CHANGELOG.md