事务
事务处理
using (TransactionScope scope = new TransactionScope())
{
context1.SaveChanges(false);
context2.SaveChanges(false);
scope.Complete();
context1.AcceptAllChanges();
context2.AcceptAllChanges();
}
using (var dbContext = new TopOnlineDbContext())
{
using (var scope = dbContext.Database.BeginTransaction())
{
try
{
if (ids != null)
{
foreach (var id in ids)
{
T t = dbContext.Find<T>(id);
assfeedback.IsDel = true;
dbContext.Update<T>(t);
}
}
scope.Commit();//正常完成就可以提交
return 0;
}
catch (Exception ex)
{
scope.Rollback();//发生异常就回滚
return -1;
}
}
}