Concurrency exceptions in Entity Framework

c# entity-framework entity-framework-6 optimistic-concurrency

Accepted Answer

DbUpdateConcurrencyException is a particular exception raised byDbContext hence, this is the fish to capture. This exception could be brought on by underlying issues.OptimisticConcurrencyException , however in that case, the inner exception is used to protect this one.

You must also catch that not all update exceptions are caused by concurrency.DbUpdateException 18 zzzz, catchingDbUpdateConcurrencyException (since it is a subtype of the former)DbUpdateException ).

Also see How is the optimistic concurrency exception handled by Entity Framework 5.0?.

5/23/2017 12:26:38 PM

Popular Answer

You'll receive anOptimisticConcurrencyException . Look at the numbers this.

Getting to the difference now

  • When an optimistic concurrency violation occurs, the exception OptimisticConcurrencyException is raised, which assumes that multiple people are modifying the same outcome and results in the problem not being synchronized.
  • DbUpdateConcurrencyException: DbContext throws an exception when, despite the fact that no database rows were actually updated, SaveChanges for an entity should have caused a database update. This demonstrates that a concurrency token that was anticipated to match did not really match and that the database has undergone concurrent updates. Due to security concerns, state entries referred to by this exception are not serialized, and attempts to access them after serialization will produce a null result.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow