EF 执行多次SaveChanges 事务

using (DbContextTransaction transaction = context.Database.BeginTransaction())
{
try
{
List<TechnicalReviewInfo> currentTR = context.TechnicalReviewInfo.Where(x => x.Guid == info.Guid && x.IsDelete == false).ToList();
foreach (TechnicalReviewInfo item in currentTR)
{
item.IsDelete = true;
}
context.TechnicalReviewInfo.Add(info);
context.WorkStep.Add(currentStep);
context.SaveChanges();

nextStep.PreStepId = currentStep.Id;
//throw new Exception();
context.WorkStep.Add(nextStep);
count = context.SaveChanges();
transaction.Commit();
}
catch (Exception)
{
transaction.Rollback();

}
}

posted @ 2020-08-07 15:45  我的女人是捡的  阅读(1307)  评论(0编辑  收藏  举报