限制查询大小与实体框架 [英] Limiting query size with entity framework

查看:119
本文介绍了限制查询大小与实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的问题(我认为),但我一直没能找到解决的办法。我知道,与其他类型的查询,您可以添加一个限制条款,使得查询只返回到许多成果。这可能与实体查询?

this is a simple question (I think), but I have not been able to find a solution. I know with other types of queries, you can add a limit clause that makes the query only return up to that many results. Is this possible with an entity query?

var productQuery = from b in solutionContext.Version
                               where b.Product.ID != 1 && b.VersionNumber == b.Product.ActiveNumber
                               orderby b.Product.LastNumber
                               select b;



我只是想使它所以这个查询仅返回25版本的对象。 。感谢您的帮助。

I just want to make it so this query only returns 25 version objects. Thanks for any help.

推荐答案

确定..例如,你可以做这样的:

sure.. for example you can do it like this:

var productQuery = from b in solutionContext.Version
                           where b.Product.ID != 1 && b.VersionNumber == b.Product.ActiveNumber
                           orderby b.Product.LastNumber
                           select b;

var limitedProductQuery = productQuery.Take(25);



你也可能需要此分页的结果:

also you may need this for paging results:

var pagedProductQuery = productQuery.Skip(25 * page).Take(25)

这篇关于限制查询大小与实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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