What NuGet package contains OptimisticConcurrencyException for DotNet Core?

.net-core c# entity-framework-core


I'm migrating code to DotNet Core. I need to resolve a reference to OptimisticConcurrencyException. What NuGet package do I need to load?

6/11/2018 1:03:07 AM

Accepted Answer

If you're migrating to EF Core, the closest you can get is DbUpdateConcurrencyException.

The general approach to handle a concurrency conflicts is:

  1. Catch DbUpdateConcurrencyException during SaveChanges.
  2. Use DbUpdateConcurrencyException.Entries to prepare a new set of changes for the affected entities.
  3. Refresh the original values of the concurrency token to reflect the current values in the database.
  4. Retry the process until no conflicts occur.

source: https://docs.microsoft.com/en-us/ef/core/saving/concurrency


OptimisticConcurrencyException is in the System.Data.Entity.Core namespace which is part of the EntityFramework (EF6) library.

EF Core is a complete rewrite of the entity framework library so it's highly likely that OptimisticConcurrencyException never went in EF Core.

There was also this thread that suggested to just catch DbUpdateConcurrencyException in EF6. And it was also pointed out that the two exceptions in EF6 just adds confusion. So maybe the EF Core team decided to just implement one over the other.

If still in doubt, create an issue in the EF Core github repo. They're receptive of answering the issues and it might help other users too with the same problem. :)

6/11/2018 1:37:53 AM

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