即使使用Skip和Take Linq-> EF返回每条记录?!? [英] Even with Skip and Take Linq->EF returns every record ?!?

查看:127
本文介绍了即使使用Skip和Take Linq-> EF返回每条记录?!?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的......也许事后回想一下,在相信它可以用Entity Framework V1创建真实世界的查询之前,我应该多考虑LINQ的真正含义。 就像我现在在爱丽丝一样。

我的情况很简单。 我有一个IQueryable查询到我的数据库有成千上万的记录。 当我使用像data = query.Skip(5).Take(10).ToList()之类的查询查询该列表时,数据对象最终有10条记录,但查看了它返回数据库中每条记录的查询!  (假设查询是从someContext中选择的东西,其中某些内容=某事等)。

由于显而易见的原因,我真的需要数据库只返回10条记录,而不是几十万条。 我已经看过ObjectQuery的例子,但它们都是基于字符串的,我喜欢强类型查询的想法,更不用说在这个实现上花费的时间。

有没有办法从我想要的东西得到强类型查询或我在这里走错了方向?  EF4会帮忙吗? 任何指导都将不胜感激。

Ok...maybe in hindsight I should have given a little more thought to what LINQ really was before believing it could create real world queries with Entity Framework V1.  Like Alice though I'm in now.

My scenario is simple.  I have an IQueryable query to my database with hundreds of thousands of records.  When I query that list with a query like data = query.Skip(5).Take(10).ToList() the data objects ends up with 10 records but having looked at the query it returned every record in the database!  (assume query is a simple select something from someContext where something = something, etc).

For obvious reasons I really need the database to only return me 10 records not a couple hundred thousand.  I've seen ObjectQuery examples but they are all string based and I like the idea of strongly typed queries not to mention the time spent on this implementation.

Is there a way to get what I want from a strongly typed query or did I go the wrong direction here?  Will EF4 help?  Any guidance would be appreciated.

推荐答案

嗯......你说,看了它返回的查询......你是什么意思? 查看名为"query"的IQueryable实例。在调试器中或查看生成的SQL语句。

为我跳过并按预期工作。 后端数据库版本也是什么?

Hmmm...You say, having looked at the query it returned...What do you mean by that?  Looked at the instance of an IQueryable named "query" in the debugger or looked at the SQL statement generated.

Skip and take work as expected for me.  What backend db version also?


这篇关于即使使用Skip和Take Linq-> EF返回每条记录?!?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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