LINQ : IEnumerable and IQueryable
IEnumerable<T> and IQueryable<T> are the two most used terms of any LINQ discussion. What I am trying to here is that I am trying to simplify the two interfaces depending on their behavior. In LINQ world we generally have few providers available within .NET Framework, like LINQ to Object, LINQ to SQL, LINQ to XML.
It is a statement that every LINQ statement returns IEnumerable<T>. IEnumerable works in steps. Meaning, when you write,
var q = from a in b
where a > 5
select a;
It creates a list out “b” depending on “where” then it creates another list for “select”. This is the behavior of LINQ to Object and LINQ to XML.
When you use LINQ to SQL it uses IQueryable<T>. This interface inherits from IEnumerable<T> but typically any LINQ to SQL generates T-SQL at the backend to be able to get the data for us. This evaluate and generates the query at one shot and gives us the whole data.
Namoskar!!!
Comments
- Anonymous
November 12, 2009
IEnumerable<T>: Iterated in-memory IQueryable<T>:
- Out-of-memory e.g. Database or WebServices
- Extends IEnumerable interface for better query support.
Anonymous
November 12, 2009
IEnumerable<T> : Iterated in-memory IQueryable<T> : Out of memory (e.g. Database or WebServices) and Extends IEnumerable interface Regards, Ajay Shankar(MCTS)Anonymous
September 03, 2011
Nice explanation. Easy to understand.Anonymous
May 17, 2013
IEnumerable<T>: Don't supports Lazy loading. IQueryable<T>: Supports Lazy Loading.Anonymous
December 14, 2016
Its a nice article you can also see more details regarding this on that Link