paginationlinq-to-sql

My Linq to SQL query paging logic is not executing in the database


How can I make my Linq to SQL query logic execute on the server?

I have a created a Linq query and returned it as an IEnumerable. Subsequent operations on the query such as .Count() or .Take(5) are evaluated on the client in CLR, rather than on the server.


Solution

  • Converting to IEnumerable will cause the query to be executed - as a result the data is now on the client side.

    If you want to execute paging on the server side, you should perform those operations while it is still a late executing IQueryable.