📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Why does calling Update() on a disconnected entity cause EF Core to write every column, and what would you do instead?

Intermediate Theory Intermediate

🎯 Key points

  • Without an original-values snapshot EF Core can't tell which properties changed
  • Every property marked Modified
  • Overwrites (loses) concurrent changes
  • Load tracked, then apply DTO
  • IsModified for targeted updates; ExecuteUpdate for set-based ones
  • RowVersion token in WHERE -> DbUpdateConcurrencyException -> 409

⏱ 30-second answer

Update() attaches the entity graph and marks every property Modified, because EF Core has no snapshot of original values to compare against, so it can't tell which properties actually changed. It sends all columns, which silently overwrites (loses) other users' concurrent edits and wastes I/O. Instead: load the entity tracked and apply the DTO's changes (only changed columns are written); or attach and set Entry(e).Property(x => x.Name).IsModified = true for specific fields; or use ExecuteUpdate for set-based changes in one statement without loading. Always add a RowVersion concurrency token ([Timestamp] byte[]): EF Core adds it to the WHERE clause and throws DbUpdateConcurrencyException if someone else changed the row, which you turn into a 409.

🔍 What the interviewer is checking

Checks understanding of disconnected updates and their risks.

↩ Usually asked after

More in Querying

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me