I'm migrating code to DotNet Core. I need to resolve a reference to OptimisticConcurrencyException
. What NuGet package do I need to load?
If you're migrating to EF Core, the closest you can get is DbUpdateConcurrencyException
.
The general approach to handle a concurrency conflicts is:
- Catch
DbUpdateConcurrencyException
duringSaveChanges
.- Use
DbUpdateConcurrencyException.Entries
to prepare a new set of changes for the affected entities.- Refresh the original values of the concurrency token to reflect the current values in the database.
- Retry the process until no conflicts occur.
source: https://docs.microsoft.com/en-us/ef/core/saving/concurrency
EDIT:
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. :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.