What is the difference between Find, Single, SingleOrDefault, First and FirstOrDefault in EF Core?

Entity Framework & EF Core Querying Intermediate 1–2 Yrs2–3 Yrs3–5 Yrs Conceptual 1 min read

Quick Answer

Find checks the change tracker first and only queries the DB on a miss (by primary key). Single/SingleOrDefault assert exactly one (or zero-or-one) match — they fetch up to 2 rows and throw if there's a second. First/FirstOrDefault just take the first match. The ...OrDefault variants return null instead of throwing on no match.

Find is special — it looks in the change tracker for an entity with that key and only goes to the database if it's not already loaded, so it can save a query. Single and SingleOrDefault mean “there should be exactly one”; they query TOP 2 and throw if a second row comes back, which is what you want when a duplicate would indicate a bug. First and FirstOrDefault just grab the first row and don't care if there are more. The OrDefault versions give you null rather than an exception when nothing matches. And First without an OrderBy is non-deterministic.

  • Find avoids a round-trip for an already-loaded entity; the others always hit the DB.
  • Use Single when “more than one” means a data-integrity bug you want surfaced; use First when duplicates are legitimate and you just want one.
  • First without OrderBy returns an arbitrary row — add an explicit order.
  • Single generates SELECT TOP 2; First generates SELECT TOP 1.