开发者

Linq Paging - How to incorporate total record count

I am trying to figure out the best way of getting the record count will incorporating paging. I need this value to figure out the total page count given a page size and a few other variables.

This is what i have so far which takes in the starting row and the page size using the skip and take statements.

promotionInfo = (from p in matches
orderby p.PROMOTION_NM descending
select p).Skip(startRow).Take(pageSize).ToList();

I know i could run another query, but figured there may be another way of achieving this count without having to run the query twice.

Thanks in 开发者_StackOverflow中文版advance, Billy


I know i could run another query, but figured there may be another way of achieving this count without having to run the query twice.

No, you have to run the query.

You can do something like:

var source = from p in matches
             orderby p.PROMOTION_NM descending
             select p;
var count = source.Count();
var promotionInfo = source.Skip(startRow).Take(pageSize).ToList();

Be advised, however, that Skip(0) isn't free.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜