LINQ Interview Question #88
What does AsEnumerable do?
Deferred Execution, Immediate Execution & Query Behavior Mid-Level Intermediate
Quick Interview Answer
AsEnumerable exposes a source as IEnumerable<T>. It does not itself copy or materialize the data.
Detailed Explanation
AsEnumerable exposes a source as IEnumerable<T>. It does not itself copy or materialize the data.
A common use with IQueryable is to intentionally switch subsequent LINQ operations from provider-based query translation to LINQ to Objects. Developers should be careful because operations after that boundary execute in application code.
Code Example
var query = db.Products
.Where(p => p.IsActive)
.AsEnumerable()
.Where(p => CustomDotNetMethod(p));