How to determine if a UnitOfWork has been committed?

Posts   
 
    
Flynn
User
Posts: 17
Joined: 28-Jan-2009
# Posted on: 14-May-2012 20:10:56   

Using LLBLGen v2.6 (see full details in signature):

I have a class which contains a UnitOfWork. Multiple object may throw events that result in entities being added to the UnitOfWork to be inserted, updated, etc. Other events may trigger the current UnitOfWork being committed to the database.

Is there a way to determine if the current contents of the UnitOfWork have been committed to the database?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-May-2012 20:54:29   

You can check the entities state in the internal queues. And you can get these Queues using functions like, GetInsertQueues() & GetUpdateQueues()... etc.

Another approach is to wrap the UoW in a custom class which manages a flag whether the UoW is dirty (Add.. methods have been called) or not (default status, or a Commit was called).

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 15-May-2012 09:09:08   

Commit returns the # of entities affected by the commit. If it's > 0, commit has ran. So you should simply use that value for determining whether it has ran already.

Frans Bouma | Lead developer LLBLGen Pro