What is the difference between IQueryable
and IEnumerable
?
See also What\'s the difference between IQueryable and I
The primary difference is that the LINQ operators for IQueryable
take Expression
objects instead of delegates, meaning the custom query logic it receives, e.g., a predicate or value selector, is in the form of an expression tree instead of a delegate to a method.
IEnumerable
is great for working with sequences that are iterated in-memory, butIQueryable
allows for out-of memory things like a remote data source, such as a database or web service.Where the execution of a query is going to be performed "in process", typically all that's required is the code (as code) to execute each part of the query.
Where the execution will be performed out-of-process, the logic of the query has to be represented in data such that the LINQ provider can convert it into the appropriate form for the out-of-memory execution - whether that's an LDAP query, SQL or whatever.
More in: