添加引用 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{}
}
http://www.keyusoft.cn/(S(prgsxrrzofjzfw45inpjehib))/UsingSubSonicToCreateASimpleBogEngine.ashx
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{}
}
http://www.keyusoft.cn/(S(prgsxrrzofjzfw45inpjehib))/UsingSubSonicToCreateASimpleBogEngine.ashx
本文介绍了一个使用C# TransactionScope来确保数据一致性的例子。通过两个OrderSellerList实例的创建与保存操作,演示了如何在一个事务范围内进行数据库操作,并在成功完成所有任务后提交这些更改。
127

被折叠的 条评论
为什么被折叠?



