Linq分页-如何合并总记录数 [英] Linq Paging - How to incorporate total record count

查看:375
本文介绍了Linq分页-如何合并总记录数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出将记录合并到页面中的最佳方法.在给定页面大小和其他一些变量的情况下,我需要此值来计算总页面数.
这是到目前为止,我使用skip和take语句获取起始行和页面大小的信息.

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.

预先感谢, 比利

推荐答案

我知道我可以运行另一个查询,但是想出了另一种无需再次运行查询就可以实现此计数的方法.

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.

否,您必须运行查询.

您可以执行以下操作:

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();

但是请注意, Skip(0)不是免费的.

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

这篇关于Linq分页-如何合并总记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆