EFPagination.Analyzers 1.0.0

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

Entity Framework Pagination (EFPagination)

Keyset pagination for Entity Framework Core. Also known as seek or cursor pagination.

Keyset pagination delivers stable query performance regardless of page depth, unlike offset pagination (Skip/Take) which degrades linearly as you skip more rows.

Installation

dotnet add package EFPagination

Requires .NET 10 and EF Core 10.

Quick Start

using EFPagination;

// Quick-start local variable; in production, build once and store as a static readonly field.
var definition = PaginationQuery.Build<User>(b => b.Descending(x => x.Created).Ascending(x => x.Id));

// First page.
var context = dbContext.Users.Paginate(definition);
var users = await context.Query.Take(20).ToListAsync();
context.EnsureCorrectOrder(users);

// Next page — pass the last item as a cursor.
var nextContext = dbContext.Users.Paginate(definition, PaginationDirection.Forward, users[^1]);
var nextUsers = await nextContext.Query.Take(20).ToListAsync();
nextContext.EnsureCorrectOrder(nextUsers);

// Check boundaries.
var hasPrevious = await nextContext.HasPreviousAsync(nextUsers);
var hasNext = await nextContext.HasNextAsync(nextUsers);

API

Paginate

Applies keyset-based ordering and filtering to a query.

// With a prebuilt definition (recommended — enables expression caching):
PaginationContext<T> Paginate<T>(
    this IQueryable<T> source,
    PaginationQueryDefinition<T> queryDefinition,
    PaginationDirection direction = PaginationDirection.Forward,
    object? reference = null);

// With an inline builder:
PaginationContext<T> Paginate<T>(
    this IQueryable<T> source,
    Action<PaginationBuilder<T>> builderAction,
    PaginationDirection direction = PaginationDirection.Forward,
    object? reference = null)

PaginateQuery

Shortcut that returns the IQueryable<T> directly when you don't need the context:

// With a prebuilt definition (recommended):
IQueryable<T> PaginateQuery<T>(
    this IQueryable<T> source,
    PaginationQueryDefinition<T> queryDefinition,
    PaginationDirection direction = PaginationDirection.Forward,
    object? reference = null);

// With an inline builder:
IQueryable<T> PaginateQuery<T>(
    this IQueryable<T> source,
    Action<PaginationBuilder<T>> builderAction,
    PaginationDirection direction = PaginationDirection.Forward,
    object? reference = null)
var query = dbContext.Users
    .PaginateQuery(definition, direction, reference)
    .Take(20);

PaginationContext<T>

Returned by Paginate.

Property Description
Query The filtered and ordered IQueryable<T>. Chain .Take(), .Select(), etc.
OrderedQuery The ordered IQueryable<T> without the pagination filter. Used internally by boundary checks.
Direction The PaginationDirection used for this call.

Extension methods on PaginationContext<T>:

Method Description
EnsureCorrectOrder<T2>(IList<T2>) Reverses the list in-place when direction is Backward. Always call after fetching.
HasPreviousAsync<T2>(IReadOnlyList<T2>) Returns Task<bool> — true if there is data before the current page.
HasNextAsync<T2>(IReadOnlyList<T2>) Returns Task<bool> — true if there is data after the current page.

PaginationQueryDefinition<T>

A prebuilt, reusable pagination definition. Build once, reuse across requests:

static readonly PaginationQueryDefinition<User> Definition =
    PaginationQuery.Build<User>(b => b.Descending(x => x.Created).Ascending(x => x.Id));

PaginationBuilder<T>

Fluent builder for defining pagination columns, used inside PaginationQuery.Build<T>():

Method Description
Ascending<TCol>(Expression<Func<T, TCol>>) Adds a column with ascending sort.
Descending<TCol>(Expression<Func<T, TCol>>) Adds a column with descending sort.
ConfigureColumn<TCol>(Expression<Func<T, TCol>>, bool isDescending) Adds a column with explicit sort direction. Useful when the direction is dynamic.

Nested properties are supported: b.Ascending(x => x.Details.Created).

IncompatibleReferenceException

Thrown when a reference object is missing a property required by the pagination definition (loose typing mismatch).

Property Description
PropertyName The property that was not found on the reference object.
ReferenceType The type of the reference object that was searched.
EntityType The entity type that defines the pagination column.

PaginationDirection

enum PaginationDirection { Forward, Backward }
  • Forward — walk in the configured sort order (toward next pages).
  • Backward — walk against the configured sort order (toward previous pages).

Documentation

Topic Description
Getting Started Installation, requirements, first query
Pagination Patterns First, last, previous, next page patterns
API Reference Full API details, nested properties, exceptions
Prebuilt Definitions Caching pagination definitions for performance
Database Indexing Composite indexes, deterministic definitions
NULL Handling Computed columns, expression coalescing
Loose Typing DTOs, projections, anonymous type references
Analyzers & Diagnostics Build-time warnings and fixes

Samples

The samples directory contains a Razor Pages demo with four pagination variations and a Minimal API endpoint showcasing loose typing with JSON cursor tokens.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.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
3.2.0 132 8/21/2026
3.1.0 127 8/21/2026
3.0.3 657 6/18/2026
3.0.2 130 5/29/2026
3.0.1 129 5/26/2026
3.0.0 126 5/14/2026
2.0.0 141 3/28/2026
1.1.3 135 3/27/2026
1.1.2 132 3/27/2026
1.1.1 132 3/27/2026
1.1.0 137 3/27/2026
1.0.0 143 2/22/2026