使用事物插入数据库
使用事物插入数据库
var context = Repository<BillRepository>().RepositoryContext; context.BeginTransaction(); try { Resolve<IAccountService>().Update(userAccount); Resolve<IAccountService>().Update(targetUserAccount); Add(sourceBill); context.SaveChanges(); context.CommitTransaction(); } catch (Exception ex) { context.RollbackTransaction(); return ServiceResult.FailedWithMessage("更新失败:" + ex.Message); } finally { context.DisposeTransaction(); }