using  System.Transactions

如果修改、删除、添加一类操作涉及到多张表,那么最好用事物 trans.Complete();保证多张表的同时修改

using (TransactionScope trans = new TransactionScope())
{
                        if (result.Result)
                        {
                            foreach (SubOrders subOrders in listSubOrders)
                            {
                                if (result.Result)
                                {
                                    result.Result = _orderDao.UpdateSubOrders(subOrders) > 0;
                                }
                            }

                        }
                        if (result.Result)
                        {
                            OrderPaymentDetails orderPaymentDetails = new OrderPaymentDetails()
                            {
                                Amount = mainOrders.TotalPay,
                                Bank = category.ToString(),
                                CreateTime = DateTime.Now,
                                MainOrderID = mainOrders.MOID,
                                Method = 1,
                                PayParam = string.Join("&", listParam)
                            };
                            result.Result = _orderDao.InsertOrderPaymentDetails(orderPaymentDetails) > 0;
                        }
                        if (result.Result)
                        {
                            trans.Complete();
                        }
}

 

相关文章:

  • 2021-08-29
  • 2021-08-22
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2021-06-04
猜你喜欢
  • 2022-12-23
  • 2022-02-05
  • 2021-11-23
  • 2022-02-04
  • 2021-11-08
  • 2021-09-26
  • 2021-12-27
相关资源
相似解决方案