subsonic 中使用事务

方法1:To Perform a Transaction With a Shared Connection

using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope()) using (TransactionScope ts = new TransactionScope()) {     Product p = new Product(1);     p.Title = "new title";

    Product p2 = new Product(2);     p.Title = "another new title";

    // ...     p.Save();     p2.Save();     ts.Close(); }

方法2:添加引用 using System.Transactions; using (TransactionScope scope = new TransactionScope())         {             try             {                 OrderSellerList osl1 = new OrderSellerList();                 osl1.OrderId = 9;                 osl1.SellerId = 2;                 osl1.UserId = 1;                 osl1.Save();                 OrderSellerList osl2 = new OrderSellerList();                 osl2.OrderId = 200;                 osl2.SellerId = 2;                 osl2.UserId = 1;                 osl2.Save();                 scope.Complete();             }             catch{}         }

方法3:Simple Pass-through Transactions //create a new command collection

QueryCommandCollection coll = new QueryCommandCollection();

 

//change some data

Product p1 = new Product(1);

p1.ProductName = "New Name";

 

Product p2 = new Product(2);

p2.ProductName = "Another new name";

 

//add the commands to the collection

//by pulling them from the objects

//can also use GetInsertCommand() and GetDeleteCommand()

coll.Add(p1.GetUpdateCommand(Environment.UserName));

coll.Add(p2.GetUpdateCommand(Environment.UserName));

 

//Hand them to the DataService to execute in the scope

//of a transaction

DataService.ExecuteTransaction(coll);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值