Approach to DB Transactions with Multiple Entities

Jul 15, 2014 at 10:39 PM
First, thank you very much for all your hard work!

You implemented explicit DB transaction handling in the UnityOfWork class via the BeginTransaction, Commit, and Rollback methods. I see and understand your example of how to use these methods in UnitOfWork_Tests.

My question is - what is the best approach to take when multiple entities are involved? The sample app contains the CustomerController, which handles transactions for customers. But, let's say you needed to wrap a transaction around updates to (1) an order and (2) its order details. Can/should this be done in one ODataController? Or, should this be done in a separate component which calls the underlying ODataControllers for orders and order details. Or, would you take a completely different approach?
Jul 16, 2014 at 6:11 PM
This should be done in the Repository or Services layer add a custom method which will take in your different entities an and do your transaction here. Avoid having this in your Controllers, since it will not be reusable there and the concern for CRUD should not be in a Controller.
Marked as answer by lelong37 on 7/16/2014 at 10:11 AM
Jul 16, 2014 at 6:45 PM
Thank you for your reply.

Since the transaction are performed by the UnitOfWork class, and each controller has its own UnitOfWork object, how would you wrap a transaction around several entities (each of which has its own controller)? How would you "share" a common UnitOfWork object?