What Is The Difference Between IEnumerable And IQueryable in C#

Forums C#What Is The Difference Between IEnumerable And IQueryable in C#
Staff asked 3 years ago

What Is The Difference Between IEnumerable And IQueryable in C#

Answers (2)

Add Answer
Staff answered 3 years ago
  • Both will query data from a database, But
    • IEnumerable executes a select query on the server-side, loads data in memory on the client-side, and then filter data.
    • IQueryable executes the select query on the server-side with all filters.
Staff answered 3 years ago

IEnumerable

IEnumerable exists in the System.Collections namespace.

IEnumerable is suitable for querying data from in-memory collections like List, Array.

IEnumerable is beneficial for LINQ to Object and LINQ to XML queries.

IEnumerable is slower than IQueryable because 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.

IQueryable

IQueryable exists in the System.Linq Namespace.

IQueryable is suitable for querying data from out-memory (like remote database, service) collections.

IQueryable is beneficial for LINQ to SQL queries.

IQueryable is faster than IEnumerable  because while querying data from a database, IQueryable executes a “select query” on server-side with all filters

 

Subscribe

Select Categories