在context.SaveChanges()其中一个例外情况下处理几个潜在的异常时OptimisticConcurrency.有关此问题的Microsoft文档,请访问http://msdn.microsoft.com/en-us/library/bb399228.aspx,对于EF 4.x进行了讨论.
try
{
// Try to save changes, which may cause a conflict.
int num = context.SaveChanges();
Console.WriteLine("No conflicts. " +
num.ToString() + " updates saved.");
}
catch (OptimisticConcurrencyException)
{
// Resolve the concurrency conflict by refreshing the
// object context before re-saving changes.
context.Refresh(RefreshMode.ClientWins, orders);
// Save changes.
context.SaveChanges();
Console.WriteLine("OptimisticConcurrencyException "
+ "handled and changes saved");
}
Run Code Online (Sandbox Code Playgroud)
...但是在EF 5.0(RC)上,这似乎不起作用,因为Refresh()我的EF5,代码优先,DbContext派生context类上不存在.
我确实看到了context.Entry(context.SalesOrderHeaders).Reload();- 但这似乎是一个直接从db重新加载而不是刷新/合并(与策略客户端获胜).
任何想法如何处理EF5中的乐观并发异常?实际上甚至在SaveChanges()中关于异常处理的一般指针都会很好
谢谢
我正在将代码迁移到 DotNet Core。我需要解决对 的引用OptimisticConcurrencyException。我需要加载什么 NuGet 包?