Learn Minimal APIs from start to finish. Perfect for beginners.

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.

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.

Download this code example

Enter your email and we'll send you a download link.