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
See a code example of how transactions are used in Entity Framework Core and how they can be committed and rolled back
Writing dynamic queries for Entity Framework. A sample .NET 5 MVC application, showing examples of LINQ expressions.
Download this code example
Enter your email and we'll send you a download link.