c# - 什么 NuGet 包包含 DotNet Core 的 OptimisticConcurrencyException?

标签 c# .net-core entity-framework-core

我正在将代码迁移到 DotNet Core。我需要解析对 OptimisticConcurrencyException 的引用。我需要加载什么 NuGet 包?

最佳答案

如果您正在迁移到 EF Core,您可以获得的最接近的是 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.

来源:https://learn.microsoft.com/en-us/ef/core/saving/concurrency

编辑:

OptimisticConcurrencyExceptionSystem.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/

相关文章:

c# - WPF Image : . Source = Clipboard.GetImage() 未显示

c# - 在 WPF 中单击按钮时创建文本框?

c# - ArrayList 与 List<object>

.net-core - 在 .NET 核心的 xunit 上下文中获取 ContentRootPath 或 IHostingEnvironment

c# - EF Core Linq 使用方法语法加入 OR 条件

c# - ProgressBar 中值为 0 时如何显示 PART_Indicator? WPF

c# - 为什么代码行为在发布和 Debug模式下不同?

azure - .NET Core 2 Service Fabric 控制台应用程序通用配置文件

c# - EF2.1 中的自由文本 : The 'FreeText' method is not supported because the query has switched to client-evaluation.

c# - 在 Entity Framework Core 中使用 Npgsql.NodaTime