mediumConceptScenarioMidSenior
A read-only endpoint that returns fifty thousand rows is slow and memory-heavy in EF Core. What is the context doing?
4 min readUpdated 2026-08-15
Answer
Short answer
The context snapshots every entity it loads so it can work out what changed at save time, which is useful for a handful of entities and pure overhead for a read.AsNoTracking removes the snapshot, and the same mechanism explains why a stray mutation on a tracked entity gets written even though you never called Update.
Was this answer helpful?
Likely follow-ups
- You never called Update and the row changed anyway. How?
- What does SaveChanges do when nothing was modified?
- Two queries return the same row. Do you get one object or two?
- When is tracking worth keeping on a large result set?
Related questions
- Two users edit the same record and both save. What does EF Core do about it?mediumAlso on ef-core and change-tracking5 min
- This EF Core query is slow. How do you work out why, and what does change tracking have to do with it?mediumAlso on ef-core and change-tracking5 min
- Your Node service has low CPU but latency spikes for every request at the same moment. What is happening?mediumAlso on performance4 min
- A Compose screen with a long list is janky while scrolling - walk through how you'd find and fix the recomposition problem causing it.mediumAlso on performance5 min