top of page
  • Writer's pictureCristian Duque

IQueryable vs IEnumerable (LINQ)

Updated: Aug 21, 2023

Let's look at two commonly used LINQ interfaces. Language Integrated Query (LINQ) is a NET framework component for working with data queries.

IEnumerable is a read-only data query interface that performs in-memory query operations. Suitable for iterating over collection items using the IEnumerator interface.

IQueryable is an interface that provides querying external data sources, such as databases, using expression trees to represent the query operations.

IQueryable implements IEnumerable, so It includes all the features provided by the latter and contains additional features.

IEnumerable fetches all the data from the server to the client and then applies filters in memory.

IQueryable executes the query with filters and lets the data provider handle query transactions and optimisation.

IQueryable supports lazy loading. Creating custom queries is not immediately executed when you define them. They are executed when you enumerate the results, using methods like ToArray, ToList or iterating through the collection items. This execution is called "deferred execution".

IEnumerable uses "immediate execution" because queries are executed instantly when any query operation is performed.

IEnumerable is in the System.Collections namespace. IQueryable is in the System.LINQ namespace.

IEnumerable is suitable for smaller data sets and performs LINQ operations in memory.

IQueryable is an excellent option for handling pagination, sorting, filtering and projection operations when working with large datasets, leading to better performance.

Checkout my video:



bottom of page