シミュレーション更新を解決する方法はありますか?Entity Frameworkのオプティミスティック同時実行性アップデートの問題を解決する
第1のユーザ要求「カテゴリ」エンティティオブジェクト、第2のユーザも同じことを行う。
2人目のユーザーがこのオブジェクトと最初のユーザーの更新を更新します。
私は同時実行モードに設定されたデータベースにフィールドタイムスタンプフィールドを持っています - 固定。
これは私が更新する方法です:
public class CategoriesRepository : BaseCategoryRepository
{
public void Update(....)
{
try
{
Category catToUpdate = (from c in Contentctx.Categories where c.CategoryID == categoryId select c).FirstOrDefault();
catToUpdate.SectionReference.EntityKey = new System.Data.EntityKey("ContentModel.Sections", "SectionID", sectionId);
if (catToUpdate != null)
{
//Set fields here....
Contentctx.SaveChanges();
}
base.PurgeCacheItems(CacheKey);
}
catch (OptimisticConcurrencyException ex)
{
}
}
}
//Contentctx comes from base class: Contentctx:
private ContentModel _contenttx;
public ContentModel Contentctx
{
get
{
if ((_contenttx == null))
{
_contenttx = new ContentModel();
}
return _contenttx;
}
set { _contenttx = value; }
}
//on Business layer:
using (CategoriesRepository categoriesRepository = new CategoriesRepository())
{
categoriesRepository.UpdateCategory(.....);
}
例外がジャンプしたことがない...
はどのように私はこれを処理する必要がありますか?
たぶんリンクはあなたを助けることができる。[方法:オブジェクトコンテキストでデータの同時実行を管理する](http://msdn.microsoft.com/en-us/library/vstudio/ bb399228(v = vs.100).aspx) – huoxudong125