protected void HandelValidSubmit(EditContext context) { using (var transaction = PinhuaContext.Database.BeginTransaction()) { var remote = PinhuaContext.RecordAdd <dto收款单, tb_收付表>(main, creating => { creating.单号 = PinhuaContext.funcAutoCode("订单号"); creating.类型 = "收款"; creating.往来 = PinhuaContext.tb_往来表.AsNoTracking().FirstOrDefault(p => p.往来号 == creating.往来号)?.简称; }); if (PinhuaContext.SaveChanges() > 0) { foreach (var localD in detailsTableDataSource) { PinhuaContext.RecordDetailAdd <dto收款单, dto收款单D, tb_收付表, tb_收付表D>(remote, localD, BeforeNewD: beforeD => { if (string.IsNullOrEmpty(beforeD.子单号)) { beforeD.子单号 = PinhuaContext.funcAutoCode("子单号"); } else { } }); } PinhuaContext.SaveChanges(); transaction.Commit(); } Navigation.NavigateTo(routeA); } }
protected void HandleValidSubmit(EditContext context) { using (var transaction = PinhuaContext.Database.BeginTransaction()) { try { var remote = PinhuaContext.RecordAdd <dto往来, tb_往来表>(main, adding => { adding.往来号 = PinhuaContext.funcAutoCode("往来号"); }); PinhuaContext.SaveChanges(); transaction.Commit(); Navigation.NavigateTo(routeA); } catch (Exception) { transaction.Rollback(); } } }