在官网中的方法是错的

官网的

 

using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope()){
   using (TransactionScope ts = new TransactionScope())
   {
       Product p = new Product.SingleOrDefault(x=>x.ProductID==1);
       p.Title = "new title";
 
       Product p2 = new Product.SingleOrDefault(x=>x.ProductID==2);
       p.Title = "another new title";
 
       // ...
       p.Save();
       p2.Save();
       ts.Complete();
  }

}


3.0中正确使用方法

 

 
using (TransactionScope ts = new TransactionScope())

{
     using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
     {
                    
     }

     ts.Complete();
}

 

所有使用都需要开启DTC

并且引用

 System.Transactions 

相关文章:

  • 2021-11-25
  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2021-12-27
猜你喜欢
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2022-01-23
相关资源
相似解决方案