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();
  }

}


3.0中正确使用方法

 

 
using (TransactionScope ts = new TransactionScope())

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

     ts.Complete();
}

 

所有使用都需要开启DTC

并且引用

 System.Transactions 

posted @ 2011-11-06 12:03  黑色  Views(347)  Comments(0Edit  收藏  举报