[英]What NuGet package contains OptimisticConcurrencyException for DotNet Core?
I'm migrating code to DotNet Core. 我正在将代码迁移到DotNet Core。 I need to resolve a reference to
OptimisticConcurrencyException
. 我需要解析对
OptimisticConcurrencyException
的引用。 What NuGet package do I need to load? 我需要加载什么NuGet包?
If you're migrating to EF Core, the closest you can get is DbUpdateConcurrencyException
. 如果您要迁移到EF Core,则最接近的是
DbUpdateConcurrencyException
。
The general approach to handle a concurrency conflicts is:
处理并发冲突的一般方法是:
- Catch
DbUpdateConcurrencyException
duringSaveChanges
.在
SaveChanges
期间捕获DbUpdateConcurrencyException
。- Use
DbUpdateConcurrencyException.Entries
to prepare a new set of changes for the affected entities.使用
DbUpdateConcurrencyException.Entries
为受影响的实体准备一组新更改。- 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 来源: 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. OptimisticConcurrencyException
位于System.Data.Entity.Core
命名空间中,该命名空间是EntityFramework
(EF6)库的一部分。
EF Core is a complete rewrite of the entity framework library so it's highly likely that OptimisticConcurrencyException
never went in EF Core. EF Core是对实体框架库的完全重写,因此很有可能
OptimisticConcurrencyException
永远不会进入EF Core。
There was also this thread that suggested to just catch DbUpdateConcurrencyException
in EF6. 还有这个线程建议在
DbUpdateConcurrencyException
中捕获DbUpdateConcurrencyException
。 And it was also pointed out that the two exceptions in EF6 just adds confusion. 并且还指出EF6中的两个例外只会增加混乱。 So maybe the EF Core team decided to just implement one over the other.
所以也许EF核心团队决定只实施一个。
If still in doubt, create an issue in the EF Core github repo. 如果仍有疑问,请在EF Core github repo中创建一个问题。 They're receptive of answering the issues and it might help other users too with the same problem.
他们接受回答问题,也可能帮助其他用户解决同样的问题。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.