EF DbContext.Set< T>仅过滤记录 [英] EF DbContext.Set<T> filtered record only

查看:144
本文介绍了EF DbContext.Set< T>仅过滤记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的EF,所以现在我使用4.2我有点温柔我只想知道什么是最好的方式,我可以限制EF只加载过滤数据,而不是从数据库中提取所有的数据,我可以看到DbContext.Set()或DbContext.Set()。AsQueryable();不知道Where的功能,但它似乎是以相同的原则工作,即已经加载了任何给定的表的所有数据,然后对它们应用过滤器不会是主要的性能命中?还是我在这里遗漏的东西?我不希望EF从表中获取所有数据,但只能过滤一次。如何解决?



谢谢

解决方案

翻译成SQL,所以如果你使用.Where()查询,它应该在不在你的应用程序的db站点上执行。请注意,如果您执行类似.ToList()/。ToArray()的方法,然后尝试在其上应用.Where(),过滤将发生在客户端站点上.ToList()将强制执行查询执行之前应用过滤器


I'm new to EF so be bit gentle right now I'm using 4.2 I just want to know what is the best way where I can restrict EF to load only filtered data instead of pulling all the data from the db and then applying filters over it.

I can see DbContext.Set() or DbContext.Set().AsQueryable(); not sure about "Where" function but it seems to be working on same principle i.e already loads all the data for any given table and then applies filters over them wouldn't this be a major performance hit? Or am I missing something here? I don't want EF to fetch all the data from table but only filtered one. how to go about it?

thanks

解决方案

Linq queries are translated to SQL so if you use .Where() on the query it should be executed on the db site not in your application. Note that if you do something like .ToList()/.ToArray() and then try applying .Where() on top of it the filtering will take place on the client site as .ToList() will force query execution prior to applying the filter

这篇关于EF DbContext.Set< T>仅过滤记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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