mediumConceptCodingMidSeniorStaff
Two users edit the same record and both save. What does EF Core do about it?
EF Core optimistic concurrency uses a rowversion or concurrency token so a stale update affects zero rows instead of overwriting another user's change. The application must then merge, retry or ask the user.
5 min readUpdated 2026-08-15Target archetype: Big Tech, Enterprise Captive, Product Startup
Answer
Short answer
Add a concurrency token such as rowversion and handle DbUpdateConcurrencyException. When two users edit the same row, EF Core detects the stale write and lets you choose merge, retry or conflict resolution.
Was this answer helpful?
Likely follow-ups
- The user should not lose the fifteen minutes of edits they just typed. What does resolution look like on their screen?
- Why is a DateTime LastModified column a weak concurrency token, and what would make it adequate?
- When would you take a pessimistic lock instead, and what does that cost under load?
- Where does the token live while the entity is edited in a disconnected web form and posted back?
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
- A flash sale decrements stock from many threads. Do you go optimistic or pessimistic, and how do you prove nothing oversold?mediumAlso on optimistic-locking and concurrency5 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
- How would you design a thread-safe component, and why is adding synchronized to every method not a design?hardAlso on concurrency7 min