title: UnitofWork [aspnetboilerplate] Transaction Management
body: <p>I am currently working on implementing aspnetboilerplate's transaction management</p>
  
  <p>Below is the method I am using to insert a order and products associated with the order</p>
  
  <pre><code>public class OrderController
  {
      IOrderAppService _orderAppService;
      public OrderController(IOrderAppService orderAppService)
      {
          _orderAppService = orderAppService;               
      }
      public void TestOrder()
      {
          _orderAppService.TestTransaction();
      }
  }
  
  
  public class OrderAppService : IOrderAppService
  {
      //repositories are injected here
  
      public void TestTransaction()
      {
          //Created 'order' and 'products' here
  
          //Committing the created objects
          CommitOrderTransaction();
  
      }
  
      private void CommitOrderTransaction()
      {
          using (var unitOfWork = _unitOfWorkManager.Begin())
          { 
              //Inserts the Order record
              CommitInsertOrderHeader(); // Order Header is saved in database by using SaveChanges() method
  
              //Inserts the Product records associated with OrderId
              CommitInsertOrderDetails(); 
  
              unitOfWork.Complete();                
          }
      }
  }
  </code></pre>
  
  <p>As the aspnetboilerplate documentation tells that,
  "if current unit of work is transactional, all changes in the transaction are rolled back if an exception occurs, even saved changes."</p>
  
  <p>In my case when an exception occurs on inserting the OrderDetails, I would like the header record to be rolled back as well but I still have the Order header record in database.</p>