开发者

COUNT(1) OVER () with Linq to Sql

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜