开发者

Does .AsQueryable() stop IEnumerable from pulling all into memory?

开发者 https://www.devze.com 2023-02-05 02:50 出处:网络
So IQueryable allows your queries to be executed at the database level rather than on an in-memory object collection like IEnumerable. If I have an IEnumerable and I call the AsQueryable() extension m

So IQueryable allows your queries to be executed at the database level rather than on an in-memory object collection like IEnumerable. If I have an IEnumerable and I call the AsQueryable() extension method on it, does that mean that it is now an IQueryable and all calls will be executed in the database? Or is the IEnumerable already loaded into memory?

I know IEnumerable has deffered execution so does that mean calling AsQueryable before iterating the collection will make all it's queries execute in the database?

Sorry, I'm new to this it is all very confusing.

PS - I'm using LINQ to Enti开发者_运维百科ties with EF 4.0.


If the object that you have (as IEnumerable<T>) also implements IQueryable<T> then you may be in luck, but in the general-case: no. Except perhaps for that corner-case it is then too late, and you can no-longer "compose" the query (i.e. add a "where" condition that will be handled by the DB). Instead, what you have is LINQ-to-Objects doing what it can to look queryable. But th data will be consumed linearly from the underlying enumerable.

0

精彩评论

暂无评论...
验证码 换一张
取 消