IEnumerable Vs IQueryable

IEnumerable  IQueryable
Namespace System.Collections Namespace System.Linq Namespace
Derives from No base interface Derives from IEnumerable
Deferred Execution Supported Supported
Lazy Loading Not Supported Supported
How does it work IEnumerable is suitable just for iterate through collection and you can not modify (Add or Remove) data IEnumerable bring ALL data from server to client then filter them, assume that you have a lot of records so IEnumerable puts overhead on your memory. Whenever we encounter to huge data with so many records so we have to reduce overhead from application. IQueryable prepares high performance in such situations (huge data) by filtering data firstly and then sending filtered data to client.
Suitable for LINQ to Object and LINQ to XML queries. LINQ to SQL queries.
Custom Query Doesn’t supports. Supports using CreateQuery and Execute methods.
Extension mehtod
Extension methods supported in IEnumerable takes functional objects. Extension methods supported in IEnumerable takes expression objects i.e. expression tree.
When to use when querying data from in-memory collections like List, Array etc. when querying data from out-memory (like remote database, service) collections.
Best Uses In-memory traversal Paging

For more visit this.

4 thoughts on “IEnumerable Vs IQueryable

  1. Rohit says:

    Nice post !!

  2. mvc4beginner says:

    how to use these examples in MVC 4 ?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.