LINQ : IEnumerable<T> and IQueryable<T>

LINQ : IEnumerable<T> and IQueryable<T>

Rate This
  • Comments 4

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.

 

image

 

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.

 

image  

Namoskar!!!

 

Leave a Comment
  • Please add 3 and 2 and type the answer here:
  • Post
  • IEnumerable<T>: Iterated in-memory

    IQueryable<T>:

    1. Out-of-memory e.g. Database or WebServices

    2. Extends IEnumerable interface for better query support.

  • IEnumerable<T> : Iterated in-memory

    IQueryable<T> : Out of memory (e.g. Database or WebServices) and Extends IEnumerable interface

    Regards,

    Ajay Shankar(MCTS)

  • Nice explanation. Easy to understand.

  • IEnumerable<T>:

    Don't supports Lazy loading.

    IQueryable<T>:

    Supports Lazy Loading.

Page 1 of 1 (4 items)