【发布时间】:2012-07-02 07:19:18
【问题描述】:
我需要更新多个更新语句,但所有更新语句都应该适用于自动性,即更新全部或不更新。
在互联网和其他一些 SO Questions 中,我找到了如何使用 Transaction,但我没有发现其中任何一个说要在一个事务中更新多个语句。 见下面三个更新语句,目前没有在事务下运行
/// this are my update calls.
var report = reportRepository.Update(reportModel);
var book = bookRepository.Update(bookModel);
var mobile = mobileRepository.Update(mobileModel);
// each Update method for all repository will looks like
public returnModel Update(someModel model)
{
// assign values from model to entity
Context.ObjectStateManager.ChangeObjectState(entity,System.Data.EntityState.Modified)
Context.SaveChanges();
}
【问题讨论】:
标签: asp.net-mvc-3 c#-4.0 entity-framework-4.1