eZeeNow.com

it's your's

What is the Difference between IEnumerable vs IQueryable?

Many developers get confused with IEnumerable and IQueryable. Both looks similar but there are major difference between these. One will execute in the server memory and another one will execute on the SQL Server(Lazy load) with the filter.

IEnumerable :

While querying data from database, IEnumerable execute select query on server side, load data in-memory on client side and then filter data. Hence does more work and becomes slow.
Doesn't Support custom Query.
Doesn't support Lazy loading.
It is in-Memory.
Extension methods supported in IEnumerable takes functional objects.

IQueryable:

While querying data from database, IQueryable execute select query on server side with all filters. Hence Query becomes fast..
It does support Custom Query by using CreateQuery and Execute methods
It does support Lazy Loading
Extension methods supported in IEnumerable takes expression objects i.e. expression tree.

When and where to use IQueryable and IEnumerable?

IEnumerable can be used while querying data from in-memory collections like List, Array etc. Where as IQueryable can be used querying data from out-memory (like remote database, service) collections.
Loading