あるユーザーが別のユーザーによってすでに更新されたEnteryを更新する場合、シミュレーションの更新をどのように解決すればよいですか?
最初のユーザーが「Category」entityobjectをリクエストし、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(.....);
}
例外がジャンプすることはありません...
これをどのように処理する必要がありますか?