开发者

COUNT(1) OVER () with Linq to Sql

开发者 https://www.devze.com 2023-01-28 16:38 出处:网络
Can I do this with Linq to SQL? select top 10 count(1) over(), * from product Today I do 2 selects, one to count and another to select the page:

Can I do this with Linq to SQL?

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

Today I do 2 selects, one to count and another to select the page:

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

The select 开发者_运维问答with count(1) over() is much better since return total count together the page. I profile the queries and putting count(1) over() dont add any millisecond to original


How about something like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消