Linq paging - get full lines

I have a question about linq. I use Skip and Take to create swap:

(from l in db.ProductList
          select l).Skip((page - 1) * row_per_page).Take(row_per_page)

This works, and I need to get the full lines of the product list in order to calculate the maximum page. I think I should use another query to count the rows, but is there another way to do this in one query above?

+5
source share
3 answers

To get the number of rows, use the extension method .Count ()

var count = (from l in db.ProductList select l).Count();
+4
source

, . . GroupBy IEnumerable > "pages". pages.Count(), . , . GroupBy .

+1

It is impossible to get both the total number of lines and a subset of "skip / take" of these lines in a single query.

Is there a reason why you need this in two queries?

0
source

All Articles