Possible Duplicate:
Better way to query a page of data and get total count in entity framework 4.1?
When implementing pagination using EF / LINQ to entities, I am familiar with using Skip()
and Take()
to decide which paginated section to display. I am also familiar with using Count()
before invoking Skip()
or Take()
to get the total number of (non-paginated) results being paged over.
My question is, does this always have to ultimately end up in 2 separate queries being sent to the db? I would think yes, since we need to invoke Count() first to get the total (SELECT COUNT(*) FROM...
), then extend the expression tree with Skip/Take, then invoke again to get the actual data (SELECT * FROM...
).
I vaguely remember reading about a trick in SQL 2k8 that made getting total row counts easier, but I doubt EF / LINQ to Entities supports this provider feature. Just asking the question to see if anyone knows how to consolidate these into a single database hit.