.NET developer

Stage 2 · Lesson 3 of 6

Deferred execution, IEnumerable and IQueryable

C# for real work: LINQ, collections, generics and async

A query does nothing when you write it. It runs when you enumerate it: in a foreach, or when you call ToList, Count, First and similar. Enumerating twice runs it twice, which against a database means two round trips.

IEnumerable<T> runs LINQ in memory with ordinary C# functions. IQueryable<T> builds an that EF Core translates into SQL, so filters run inside . Once something becomes an IEnumerable, every later step runs in your app over whatever was already loaded.

This is why a helper that accepts IEnumerable<Order> and then filters can quietly pull a million rows into memory. Learning this now saves you from the most common EF Core performance bug in stage 4.

Common trapreturning a deferred query from a method after its has been disposed.

A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

Practise

  • Keep going on the C# track: the later exercises lean on LINQ, generics and dictionaries

  • Solve easy array and hash map problems in C# to make collections and LINQ automatic

Keep handy

  • Return to the official C# modules on collections, LINQ and async when something is unclear

Also worth your time

Mark this stage as not done?