Entity framework paging with extension method is slow?

后端 未结 1 1948
一整个雨季
一整个雨季 2021-01-13 04:43

I have some problems with a slow query in Entity Framework in C#. I have created an extension method called Page to handle paging, but when I use it the query gets really sl

相关标签:
1条回答
  • 2021-01-13 05:10

    Your extension method should be over IQueryable so that EF can process the expression and generate the SQL query with pagination.

    Since your using IEnumerable, the Page method will invoke Skip and Take of IEnumerable. This will cause enumeration of the result of the query that was built up to that point (before the call to Page) and make the pagination in memory, over all the returned items, instead of including pagination on the DB query.

    0 讨论(0)
提交回复
热议问题