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();
}
}