|Its Interface supports a simple iteration over a non-generic collection.||
Provides functionality for evaluating queries against a specific data source wherein the type of the data is not specified.
IQueryable, which adds two key methods: CreateQuery<T> and Execute<T>. Both of these methods accept an Expression, which is basically a new set of classes that allow you to express things like method calls, operations, lambda functions, etc, as a tree of expressions.
By using IQueryable you can look inside of the LINQ query, and do things with the expression tree, perhaps so your operation now uses the index. The user now gets the benefit of the index, without even needing to know about it!
|Best suitable for:||
|Traversal:||It is a forward only collection.||
A list that is the actual querying took place and you get the results.
ToList is issued to force running the query and returning these enumerable results...
|A "queryable" that is a query you could still be enriched before really sending it to the server.|
|When to use:||Use IEnumerable/ToList if you want to return a list that has been retrieved from the Database.||Use IQueryable if you want to return a base query that could be further enhanced before running it server side (by enumerating its items).|
|Derives from:||No base interface||Derives from IEnumerable|
|Processing Items:||IEnumerable can move forward only over a collection, it can’t move backward and between the items.||IQueryable can move forward, backward and between the items.|
|Moving Items:||Only supports moving to next item.||Can move items in the collection.|
|Searching:||It will process all records one by one in the forward direction, will be done.||Perform a faster search.|
|Filtering:||IEnumerable filters record on client side.||IQueryable executes select query on the server side with all filters.|
|Indexing:||Indexing is provided by default.||Support indexing by default.|
|How it works:||While query data from the database, IEnumerable execute a select query on the server side, load data in memory on the client side and then filter data.||While query data from the database, IQueryable execute a select query on the server side and filter data on the server itself.|
|Performance:||Slower that IQueryable||Faster that IEnumerable|
|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.|
|Deferred Execution:||IEnumerable supports deferred execution.||IQueryable supports deferred execution|
|Custom Query:||IEnumerable doesn’t supports custom query.||IQueryable supports custom query using CreateQuery and Execute methods.|
|Lazy Loading:||IEnumerable doesn’t support lazy loading. Hence not suitable for paging like scenarios.||IQueryable support lazy loading. Hence it is suitable for paging like scenarios.|
|Extension method:||Extension methods support by IEnumerable takes functional objects.||Extension methods support by IQueryable takes expression objects means expression tree.|
|Whatever IEnumerable can do, IQueryable can also do.||Whatever IEnumerable can do, IQueryable can also do.|