IEnumerable Vs IQueryable
Posted By :
Bipul Kumar Tiwari,
IEnumerable and IQueryable are used for data manipulation in LINQ from the database and collections.
The major difference are:
IEnumerable
|
IQueryable
|
IEnumerable exists in System.Collections Namespace. |
IQueryable exists in System.Linq Namespace. |
IEnumerable have No base interface. |
IQueryable Derives from IEnumerable . |
IEnumerable not supported Lazy Loading . Hence not suitable for paging like scenarios. |
IQueryable supported Lazy Loading . |
While querying data from the database, IEnumerable executes "select query" on the server-side, loads data in-memory on the client-side and then filters the data. Hence does more work and becomes slow. |
While querying data from a database, IQueryable executes a "select query" on server-side with all filters. Hence does less work and becomes fast. |
IEnumerable Suitable for LINQ to Object and LINQ to XML queries. |
IQueryable is suitable for LINQ to SQL queries. |
IEnumerable Doesn’t support Custom Query. |
IQueryable Supports Custom Query using CreateQuery and Execute methods.. |