We use IEnumerable
and IQueryable
to manipulate the data that is retrieved from database. IQueryable
inherits from IEnumerable
, so IQueryable
does contain all the IEnumerable
features. The major difference between IQueryable
and IEnumerable
is that IQueryable
executes query with filters whereas IEnumerable
executes the query first and then it filters the data based on conditions.
Find more detailed differentiation below :
IEnumerable
IEnumerable
exists in the System.Collections
namespaceIEnumerable
execute a select query on the server side, load data in-memory on a client-side and then filter dataIEnumerable
is suitable for querying data from in-memory collections like List, ArrayIEnumerable
is beneficial for LINQ to Object and LINQ to XML queriesIQueryable
IQueryable
exists in the System.Linq
namespaceIQueryable
executes a 'select query' on server-side with all filtersIQueryable
is suitable for querying data from out-memory (like remote database, service) collectionsIQueryable
is beneficial for LINQ to SQL queriesSo IEnumerable
is generally used for dealing with in-memory collection, whereas, IQueryable
is generally used to manipulate collections.