.NET Developer Interview Question

How does change tracking work in EF Core, and when do you turn it off?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

When EF Core loads entities through a tracking query, the DbContext keeps a snapshot of their original values. When you call SaveChanges, it compares current values against those snapshots, works out what changed and generates the inserts, updates and deletes. That costs memory and CPU, so read only queries should use AsNoTracking. For bulk work, recent versions offer ExecuteUpdate and ExecuteDelete, which run in the database without loading entities.

Why interviewers ask this

Change tracking is what makes EF Core convenient and also what makes careless EF Core code slow. The interviewer wants to know how SaveChanges decides what to write, why long lived contexts grow and slow down, and when to opt out. Mentioning set based updates shows you know that loading ten thousand entities to change one column each is the wrong tool, and that you understand those updates bypass tracked state.

How to structure your answer

  • Explain snapshots and how SaveChanges detects changes.
  • Cover entity states and disconnected entities.
  • Explain the cost, and when to use AsNoTracking.
  • Mention set based updates for bulk work.

Example answer

Spoken example, first person

When I run a normal query, EF Core attaches each entity to the context and stores a snapshot of its original values. I change properties in plain C#, and when I call SaveChanges it runs change detection, comparing every tracked entity with its snapshot, works out which are added, modified or deleted, and generates the SQL inside a transaction. All of that costs memory and CPU, roughly in proportion to the number of tracked entities, so for read only work, like an endpoint that returns a list, I use AsNoTracking, which makes a noticeable difference on large result sets. It is also why contexts should be short lived; one kept alive through a long batch job keeps accumulating entities and slows down with every save. For disconnected updates arriving from an API, I either load and modify, or attach the entity and mark what changed. For bulk changes I use ExecuteUpdate or ExecuteDelete, which run one statement in the database, though they bypass tracked entities, so I use them deliberately.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • What is the difference between Attach, Update and loading then modifying?
  • How would you process a million rows with EF Core without running out of memory?
  • What does AsNoTrackingWithIdentityResolution do?

Related .net developer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot