IEnumerable<T> represents objects enumerated in .NET; its LINQ delegates run in the process. IQueryable<T> carries an expression tree that a provider such as EF Core can translate to SQL. Example: var rows = await db.Orders .Where(x => x.Total >= minimum) .OrderByDescending(x => x.CreatedAt) .Select(x => new OrderDto(x.Id, x.Total)) .Take(50).ToListAsync(ct); Calling ToList or AsEnumerable too early moves later filtering into memory. Do not expose IQueryable across an API boundary. Compose and execute a bounded query inside the persistence layer, project only required columns, and return materialized DTOs.
Backbencher Developer · · 0 likes