C# IEnumerable vs IQueryable with EF Core: in-memory filtering vs SQL

C# Language Interview Q&A November 13, 2026 csharp

IQueryable holds an expression tree that the provider (EF Core) translates to SQL.

csharp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
// ======================================================================
// Q: IEnumerable vs IQueryable?
//
// IQueryable<T> holds an expression tree that the provider (EF Core) translates
// to SQL. IEnumerable<T> runs Where / Select in memory.
// That is why a repository returning IEnumerable from "GetAll" is a performance
// trap. IList / List: a materialized in-memory collection, with indexing and
// Count.
// ======================================================================

// ✗ the Where runs in memory: SELECT * FROM orders, then filtering in C#
IEnumerable<Order> all = db.Orders;
var big = all.Where(o => o.TotalNet > 1000).ToList();

// ✓ WHERE total_net > 1000 in the database
IQueryable<Order> query = db.Orders;
var big2 = query.Where(o => o.TotalNet > 1000).ToList();