Skip to content

KeysetEngineHigh-Performance Keyset Pagination & Search

Database-agnostic, zero-degradation pagination with cryptographic cursors for .NET 8, 9, and 10 with EF Core.

Quick Look ​

csharp
// 1. Configure pagination boundary in Program.cs
builder.Services.AddKeysetPagination(options =>
{
    options.Configure<Order>(builder => builder
        .SortBy(x => x.CreatedAt, ascending: false)
        .TieBreakBy(x => x.Id)
        .SearchIn(x => x.CustomerName, x => x.OrderNumber));
});

// 2. Query in an ASP.NET Core Minimal API
app.MapGet("/api/orders", async (
    [AsParameters] KeysetRequest request,
    AppDbContext db,
    ICursorProtector protector,
    CancellationToken ct) =>
{
    var page = await db.Orders
        .AsNoTracking()
        .ToKeysetPageAsync(request, protector, ct);

    return Results.Ok(page);
});

High Throughput at Deep Offsets

Unlike standard SQL OFFSET 100000 LIMIT 20 which forces your database engine to scan and discard 100,000 index entries, KeysetEngine translates queries directly into composite index seeks:

sql
WHERE ("CreatedAt" < @val) OR ("CreatedAt" = @val AND "Id" < @tieVal)
ORDER BY "CreatedAt" DESC, "Id" DESC
LIMIT 21

Execution time remains consistently under 1 millisecond, regardless of table size.

Released under the MIT License.