Merge UnitOfWork2

Posts   
 
    
jovball
User
Posts: 443
Joined: 23-Jan-2005
# Posted on: 03-Aug-2012 15:48:32   

I have two classes that are creating UnitOfWork2 objects. I would like to combine those into a single UnitOfWork2 (or at least execute the queries in a single transaction).

What is the best way to accomplish this?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Aug-2012 01:39:50   

There is no an explicit method to merge to UnitOfWork objects. You can do it manually though: retrieving the elemensTo/Insert/Delete/Update and then adding them to the second uow.

As you want to save them in one transaction, you can start a transaction outside and pass it to the commit method of the uow's. As the transaction is already started, uow will use that and won't start a new one. Example:

using (var adapter = new DataAccessAdapter())
{
    adapter.StartTransaction(IsolationLevel.Serializable, "TwoUowInARowTx");

    uow1.Commit(adapter);
    uow2.Commit(adapter);

    adapter.Commit();
}
David Elizondo | LLBLGen Support Team
jovball
User
Posts: 443
Joined: 23-Jan-2005
# Posted on: 09-Aug-2012 18:54:00   

Thanks, daelmo. The code example gave me the right idea for what I should be doing in this application. That is better than a merge.