Skip to content

Immediate operators

Context: Immediate operators execute the query immediately and return a concrete result (e.g., list, single value, dictionary).

var numbers = new[] { 1, 2, 3 };
var list = numbers.Where(n => n > 1).ToList(); // executes now
var first = numbers.First(); // executes now
  • ToList(), ToArray(), ToDictionary(), ToHashSet()
  • First(), FirstOrDefault(), Last(), Single()
  • Count(), Sum(), Average(), Min(), Max()
  • Any(), All(), Contains()

Materializing results for caching: Use ToList() to execute a query once and store the result, avoiding repeated database calls.

Example: In ASP.NET Core, you might materialize a query to cache the data.