EF DbContext.Set<T> filtered record only

自古美人都是妖i 提交于 2019-12-13 02:36:06

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/9362145/ef-dbcontext-sett-filtered-record-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!