COUNT (1) OVER () with Linq to Sql

Can this be done with Linq to SQL?

select top 10 count(1) over(), * from product

Today I make 2 choices, one for counting and another for page selection:

  • select count(1) from product
  • select top 10 * from product

Choosing with is count(1) over()much better, since the inverse of the total sums the page. I look through the requests and put count(1) over()without adding a single millisecond to the original

+3
source share
1 answer

How about something like this:

ctx.Products.Take(10).Select(p => new {Total = ctx.Products.Count, Product = p})
+2
source

Source: https://habr.com/ru/post/1777649/


All Articles