mediumConceptScenarioMidSeniorStaff
This EF Core query is slow. How do you work out why, and what does change tracking have to do with it?
EF Core query performance starts with the generated SQL, then checks N+1 queries, cartesian Include joins, over-fetching and change tracking. Use projections and AsNoTracking when the result is read-only.
5 min readUpdated 2026-08-15
Answer
Short answer
Inspect the SQL before changing LINQ. Fix missing indexes or bad predicates in the database, remove lazy-loading N+1s, project only needed columns, and turn off tracking for read-only results.
Was this answer helpful?
Likely follow-ups
- When does AsNoTracking give you the wrong results, and what does AsNoTrackingWithIdentityResolution change?
- Why can an Include of two collection navigations make a query slower than two separate round trips, and what does AsSplitQuery do about it?
- If tracking is the bottleneck in a bulk import, what do you change other than the query?
- How would you confirm the fix is real rather than a warm-cache illusion?
Related questions
- A read-only endpoint that returns fifty thousand rows is slow and memory-heavy in EF Core. What is the context doing?mediumAlso on ef-core and change-tracking4 min
- Two users edit the same record and both save. What does EF Core do about it?mediumAlso on ef-core and change-tracking5 min
- A Spring Data repository method looks like one clean line, but the endpoint issues several hundred queries per request. How do you diagnose the N+1, and what would you actually change?hardAlso on n-plus-one4 min
- A list endpoint that returns fifty orders issues more than a hundred queries, and rewriting it as an async endpoint made it slower. Explain both.hardAlso on n-plus-one5 min