EF DbContext.Set仅过滤记录
我是 EF 新手,所以现在要温和一些,我正在使用 4.2 我只是想知道限制 EF 仅加载过滤数据而不是从数据库中提取所有数据然后应用过滤器的最佳方法是什么超过它。
我可以看到 DbContext.Set() 或 DbContext.Set().AsQueryable();不确定“Where”函数,但它似乎按照相同的原理工作,即已经加载任何给定表的所有数据,然后对它们应用过滤器,这不会对性能造成重大影响吗?或者我在这里遗漏了什么?我不希望 EF 从表中获取所有数据,而只希望过滤一项。该怎么办呢?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Linq 查询被转换为 SQL,因此如果您在查询上使用 .Where(),它应该在数据库站点上执行,而不是在您的应用程序中执行。请注意,如果您执行类似 .ToList()/.ToArray() 的操作,然后尝试在其之上应用 .Where() ,则过滤将在客户端站点上进行,因为 .ToList() 将在应用之前强制执行查询筛选
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