LINQ:寻呼tecnique,使用取并跳过但需要总记录也 - 如何实现这一点? [英] LINQ: Paging tecnique, using take and skip but need total records also - how to implement this?

查看:149
本文介绍了LINQ:寻呼tecnique,使用取并跳过但需要总记录也 - 如何实现这一点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用跳过和采取执行寻呼程序。它的伟大工程,但我需要的表中的记录总数呼吁采取和跳过之前。

I have implemented a paging routine using skip and take. It works great, but I need the total number of records in the table prior to calling Take and Skip.

我知道我可以提交2个独立的查询。

I know I can submit 2 separate queries.


  1. 获取计数

  2. 跳过并以

不过,我宁愿不发出2调用LINQ。

But I would prefer not to issue 2 calls to LINQ.

我怎样才能返回它在同一个查询(例如,使用嵌套查询语句)?

How can I return it in the same query (e.g. using a nested select statement)?

以前,我在存储过程中使用了分页技术。我通过使用临时表中返回的项目,我通过计数的输出参数。

Previously, I used a paging technique in a stored procedure. I returned the items by using a temporary table, and I passed the count to an output parameter.

推荐答案

我很抱歉,但你不能。 。至少,在一个漂亮的方式

I'm sorry, but you can't. At least, not in a pretty way.

您可以做到这一点在unpretty方式,但我不认为你这样的:

You can do it in an unpretty way, but I don't think you like that:

var query = from e in db.Entities where etc etc etc;

var pagedQuery = 
    from e in query.Skip(pageSize * pageNumber).Take(pageSize)
    select new
    {
        Count = query.Count(),
        Entity = e
    };

您看到了吗?不漂亮的。

You see? Not pretty at all.

这篇关于LINQ:寻呼tecnique,使用取并跳过但需要总记录也 - 如何实现这一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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