Check out my book "Hands-On RESTful Web Services with ASP.NET Core" available on Amazon or Packt. Source code available on GitHub

IEnumerable and IQueryable are interfaces that allows you to manipulate and query collections of data. IEnumerable is inherited by IQueryable, that means IQueryable add features to IEnumerable interface.

IEnumerable vs IQueryable

 IEnumerable IQueryable
 System.Collections namespace  System.Linq namespace
 LINQ to Object and LINQ to XML  LINQ to SQL
 NO lazy loading  lazy loading
 in-memory queries  out-memory (serverside) queries
 doesn’t support custom query  supports custom query

Reference code from microsoft reference source

The following code shows the implementation of the IQueryable.Take() method.
The method creates a query on source provider to return top N elements.

The following code shows the implementation of the IEnumerable.Take() method.
The method simply uses a foreach to return the top N elements.


The following example shows the difference between IQueryable and IEnumerable:

The first statement uses the IQueryable interface, in fact it performs a query on data source and assigns the result to an IEnumerable variable.
The next operation is executed in-memory because they queriy use IEnumerable interface.

We can use SQL profiler to monitor the executed query:

We can perform the same operations using IQueryable interface, all queries will be performed on data source:

The SQL query will filter the result, and will use the SQL statement “TOP(100)”:

About Samuele Resca

Samuele Resca is an Microsoft MVP Visual Studio and Development Technologies, Software Engineer, specializing mainly on ASP.NET MVC and in general about everything that revolves around the web. Samuele was born in 1994, and works as a software developer @ YOOX NET-A-PORTER Group He loves the MVC frameworks, ASP.NET MVC, Javascript, Node.js and Typescript.