EF DbContext.Set< T>仅过滤记录 [英] EF DbContext.Set<T> filtered record only
问题描述
谢谢
翻译成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屋!