我正在将代码迁移到 DotNet Core。我需要解析对 OptimisticConcurrencyException
的引用。我需要加载什么 NuGet 包?
最佳答案
如果您正在迁移到 EF Core,您可以获得的最接近的是 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.
来源:https://learn.microsoft.com/en-us/ef/core/saving/concurrency
编辑:
OptimisticConcurrencyException
在 System.Data.Entity.Core
中命名空间,它是 EntityFramework
(EF6) 库的一部分。
EF Core 是对 Entity Framework 库的完全重写,因此 OptimisticConcurrencyException
很可能从未出现在 EF Core 中。
还有 this thread建议在 EF6 中捕获 DbUpdateConcurrencyException
。并且还指出,EF6 中的两个异常只会增加困惑。因此,也许 EF Core 团队决定只实现其中一个。
如果仍有疑问,请在 EF Core github 存储库中创建问题。他们乐于回答问题,这也可能会帮助其他用户解决同样的问题。 :)
关于c# - 什么 NuGet 包包含 DotNet Core 的 OptimisticConcurrencyException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50789338/