d use
keyset pagination when navigation to the next/previous page, and offset
navigation when jumping to any other page.

###  Multiple pagination keys

When using keyset pagination, it's frequently necessary to order by more than
one property. For example, the following query paginates by date and ID:

    
    
    var lastDate = new DateTime(2020, 1, 1);
    var lastId = 55;
    var nextPage = context.Posts
        .OrderBy(b => b.Date)
        .ThenBy(b => b.PostId)
        .Where(b => b.Date > lastDate || (b.Date == lastDate && b.PostId > lastId))
        .Take(10)
        .ToList();
    

This ensures that the next page picks off exactly where the previous one
ended. As more ordering keys are added, additional clauses can be added.

Note

Most SQL databases support a simpler and more efficient version of the above,
using _row values_ : ` WHERE (Date, Id) > (@lastDate, @lastId) ` . EF Core
does not currently support expressing this in LINQ queries, this is tracked by
[ #26822 ](https://github.com/dotnet/efcore/issues/26822) .

##  Indexes

As with any other query, proper indexing is vital for good performance: make
sure to have indexes in place which correspond to your pagination ordering. If
ordering by more than one column, an index over those multiple columns can be
defined; this is called a _composite index_ .

For more information, [ see the documentation page on indexes
](../modeling/indexes) .

##  Additional resources

  * To learn more about the shortcomings of offset-based pagination and about keyset pagination, [ see this post ](https://use-the-index-luke.com/no-offset) . 
  * [ .NET Data Community Standup session ](https://www.youtube.com/watch?v=DIKH-q-gJNU) where we discuss pagination and demo all the above concepts. 
  * [ A technical deep dive presentation ](https://www.slideshare.net/MarkusWinand/p2d2-pagination-done-the-postgresql-way) comparing offset and keyset pagination. While the content deals with the PostgreSQL database, the general information is valid for other relational databases as well. 
  * For extensions on top of EF Core which simplify keyset pagination, see [ MR.EntityFrameworkCore.KeysetPagination ](https://github.com/mrahhal/MR.EntityFrameworkCore.KeysetPagination) and [ MR.AspNetCore.Pagination ](https://github.com/mrahhal/MR.AspNetCore.Pagination) . 

Collaborate with us on GitHub

The source for this content can be found on GitHub, where you can also create
and review issues and pull requests. For more information, see [ our
contributor guide
](https://learn.microsoft.com/contribute/content/dotnet/dotnet-contribute) .

![](https://learn.microsoft.com/media/logos/logo_net.svg)
![](https://learn.microsoft.com/media/logos/logo_net.svg)

.NET

[ Open a documentation issue  ]() [ Provide product feedback
](https://github.com/dotnet/efcore/issues/new/choose)

##  Feedback

Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the
feedback mechanism for content and replacing it with a new feedback system.
For more information see: [ https://aka.ms/ContentUserFeedback
](https://aka.ms/ContentUserFeedback) .

Submit and view feedback for

[ This product  ](https://github.com/dotnet/efcore/issues/new/choose) This
page

[ View all page feedback
](https://github.com/dotnet/EntityFramework.Docs/issues)

* * *

##  Additional resources

[ California Consumer Privacy Act (CCPA) Opt-Out Icon  Your Privacy Choices
](https://aka.ms/yourcaliforniaprivacychoices)

Theme

  * Light 
  * Dark 
  * High contrast 

  *   * [ Previous Versions ](/en-us/previous-versions/)
  * [ Blog ](https://techcommunity.microsoft.com/t5/microsoft-learn-blog/bg-p/MicrosoftLearnBlog)
  * [ Contribute ](/en-us/contribute/)
  * [ Privacy ](https://go.microsoft.com/fwlink/?LinkId=521839)
  * [ Terms of Use ](/en-us/legal/termsofuse)
  * [ Trademarks ](https://www.microsoft.com/legal/intellectualproperty/Trademarks/)
  * © Microsoft 2024 

##  Additional resources

###  In this article

[ California Consumer Pri