使用实体框架选择范围
我在尝试最大化具有页面的列表视图的性能时遇到问题。
我希望实体框架执行 select 语句,但只返回结果的范围(范围=列表视图一页的项目)。
我已经搜索过谷歌但没有找到任何关于此的结果。我只发现我可以执行 .ToList().GetRange(start index, end index),但随后所有项目都会加载到内存中,这就是我想避免的......
有人可以告诉我这是否可以做吗? (我不想使用存储过程或视图或类似的东西,因为我们的列表视图必须可重用......)
谢谢!
I have an issue trying to maximize the performance of our listview that has pages.
I want the entity framework to do a select statement, but only return a range of the result (range = the items of one page of the listview).
I have searched google but didn't find any results on this. I only found that I can do a .ToList().GetRange(start index, end index), but then all items would be loaded in memory, and that is what I would like to avoid...
Can someone tell me if this can be done? (I don't want to use a stored procedure or view or something like that because our listview has to be reusable...)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 .Skip(startPosition).Take(numberOfItems).ToList()
Use
.Skip(startPosition).Take(numberOfItems).ToList()
如果您不使用延迟加载,请务必在应用过滤器时在 Load() 之前使用 Query() 以避免在应用过滤器之前加载整个集合:
使用 Query 方法时,通常最好关闭导航属性的延迟加载。这是因为否则整个集合可能会通过延迟加载自动加载
在执行过滤查询之前或之后的机制。
有关更多详细信息: http://msdn.microsoft.com/en-us/data /jj574232.aspx
And if you are not using lazy loading be sure to use Query() before Load() when applying filters to avoid loading the whole collection before applying filters :
When using the Query method it is usually best to turn off lazy loading for the navigation property. This is because otherwise the entire collection may get loaded automatically by the lazy loading
mechanism either before or after the filtered query has been executed.
For more details : http://msdn.microsoft.com/en-us/data/jj574232.aspx