Keyset vs offset pagination in EF Core
You can use keyset or offset pagination in Entity Framework Core to return paginated results sets.
Learn more about the differences between keyset and offset pagination, or watch the video.
Download the code example
You'll need to fill out the code example form. We will send you an email where you can download the code example.
Software
This is the software that will need to be installed onto your machine.
Visual Studio 2026. Version 18.0.0 or above. It will work with the free community version.
.NET 10 SDK. Version 10.0.0 or above.
Import the database
This application integrates with a SQL Server database. Inside the Database folder, there is RoundTheCode_EFCoreKeysetPagination.bacpac and RoundTheCode_EFCoreKeysetPagination.bak. Use either of these database backups to import the database to your local SQL Server database server.
You can import 3 million product records by running the script inside the Database/Scripts folder.
The application
Inside src/Api/appsettings.Development.json, find ConnectionStrings.EFCoreKeysetPaginationDbContext and point the connection string to your imported database.
Open up RoundTheCode.EFCoreKeysetPagination.slnx, and run the application. The Swagger documentation will load at https://localhost:7045/swagger with these endpoints:
/api/products/keyset (POST)- Returns a paginated results set using keyset pagination/api/products/offset (POST)- Returns a paginated results set using offset pagination
Download this code example
Enter your email and we'll send you a download link.
Related code examples
Download a .NET 10 sample project demonstrating Global Query Filters in Entity Framework Core, including soft delete and multitenancy, and run it in Visual Studio to see how they work in practice.
Learn how to add Entity Framework Core migrations in an Web API and worker project and use it to automate SQL scripts across all environments.
Download this code example
Enter your email and we'll send you a download link.