いくつかの潜在的な例外を処理するときcontext.SaveChanges()
、例外の 1 つが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");
}
Refresh()
...しかし、EF 5.0 (RC) では、私の EF5、コードファースト、DbContext 派生context
クラスには存在しないため、これは機能しないようです。
わかりますcontext.Entry(context.SalesOrderHeaders).Reload();
-しかし、それは更新/マージではなく、まっすぐなdbからのリロードであるように見えます(ポリシークライアントが勝つ)。
EF5 でオプティミスティック同時実行例外を処理する方法はありますか? 実際には、SaveChanges() での例外処理に関する一般的なポインターでさえいいでしょう
ありがとう