Yes it's possible (another example here: Better way to query a page of data and get total count in entity framework 4.1?), but not recommended. It usually takes contrived query constructs to get the count and the data in one LINQ statement (David's answer evades that by only selecting child items).
You better create an IQueryable
and get its count and its paged subset separately.
Even better, add PagedList to your project and use code like:
var prd = Products.Where(p => p.Categories.Any(c => c.CategoryName == "Sports" ));
var page = prd.OrderBy(p => p.Name).ToPagedList(5,500);
This simply executes the count and a Skip/Take
query to get page 5 of all pages containing 500 items.
The result, an IPagedList<T>
, is an IEnumerable<T>
that has some useful properties like HasNextPage
or PageCount
.