65.9K
CodeProject is changing. Read more.
Home

IEnumerable Vs IQueryable

Feb 24, 2014

CPOL

1 min read

viewsIcon

263859

IEnumerable Vs IQueryable

Many developers get confused between IEnumerable and IQueryable. When it comes to writing code, both look very similar. However, there are many differences between them which need to be taken care of while writing code. Both have some intended usability scenarios for which they are made.

Listed below are the differences between them based on their properties:

  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 While querying data from database, IEnumerable executes select query on server side, load data in-memory on client side and then filter data. Hence does more work and becomes slow. While querying data from database, IQueryable executes select query on server side with all filters. Hence does less work and becomes fast.
Suitable for LINQ to Object and LINQ to XML queries LINQ to SQL queries
Custom Query Doesn’t support Supports using CreateQuery and Execute methods
Extension method
parameter
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