using System.Transactions; // publicvoid Insert(PetShop.Model.OrderInfo order) { using (TransactionScope ts =new TransactionScope(TransactionScopeOption.Required)) { dal.Insert(order); // Update the inventory to reflect the current inventory after the order submission Inventory inventory =new Inventory(); inventory.TakeStock(order.LineItems); // Calling Complete commits the transaction. // Excluding this call by the end of TransactionScope's scope will rollback the transaction ts.Complete(); } }
using(TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
{
//...
ts.Complete();
}