Friday, 20 July 2018

Difference between Ienumerable and Iqueryable



IEnumerable and IQueryable are used for data manipulation in LINQ from the database and collections.




IEnumerable
  1. IEnumerable exists in the System.Collections namespace.
  2. IEnumerable is suitable for querying data from in-memory collections like List, Array and so on.
  3. While querying data from the database, IEnumerable executes "select query" on the server-side, loads data in-memory on the client-side and then filter the data. 
  4. IEnumerable is beneficial for LINQ to Object and LINQ to XML queries.
  5. If you create an IEnumerable, then all rows will be pulled into memory as objects before running the query.
IQueryable

  1. IQueryable exists in the System.Linq Namespace.
  2. IQueryable is suitable for querying data from out-memory (like remote database, service) collections.
  3. While querying data from a database, IQueryable executes a "select query" on server-side with all filters.
  4. IQueryable is beneficial for LINQ to SQL queries.
  5. If you create an IQueryable, then the query may be converted to SQL and run on the database server

No comments:

Post a Comment