Does AsEnumerable() cache all result (LINQ)

Posted by Akshay on Stack Overflow See other posts from Stack Overflow or by Akshay
Published on 2010-05-24T06:28:30Z Indexed on 2010/05/24 6:31 UTC
Read the original article Hit count: 221

Filed under:
|

When we call a query operator on a sequence, a sequence-specific operator gets called.
I mean if i call Where<>() operator on IEnumerable<>, the operator that will be called will be defined in Enumerable class and if it's called on IQueryable<>, the one defined in Queryable class will be called.

Consider the operator Reverse, defined in the Enumerable class.
If i want to call it on Iqueryable<> then I must use the AsEnumerable<>() operator to first convert it into IEnumerable<>.

db.Countries.OrderBy(cntry=>cntry.CountryName).AsEnumerable().Reverse()

But the Reverse operator got to have all records at the same time so that it can reverse them.
In the above code do all the records get loaded in memory first and then the Reverse() operator is reversing it ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-sql