Subsonic3.0 使用TransactionScope 方法
在官网中的方法是错的
官网的
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();
}
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 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号