backendgym backendgym · reps Sign in with GitHubSign in

03When the query runs

csharp-reading / reps/03/README.md

Read Program.cs first, then run it: dotnet run --project reps/03. It prints:

query defined
  testing 1
  testing 2
  testing 3
  testing 5
first pass: 1,3,5
  testing 1
  testing 2
  testing 3
  testing 5
second pass: 1,3,5

Two things in it surprise most readers: 5 is in the result although it was added to the list after the query was written, and the testing lines appear twice.

After the rep
  1. 1 Both surprises come from one fact about what Where returned. Put it in one sentence.
  2. 2 A method returns IEnumerable<T> from a Where over a database context, and the caller enumerates it twice. What do you tell them, and what should the method return instead?