Adapter, UOW, how to remove elements from delete collection

Posts   
 
    
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 04-Mar-2013 12:36:52   

Hi,

I have a situation in which two different modules of codes inserts and after some time deletes entity from UOW. So it creates unnecessery db operations. I have a wrapper around the UOW and want to check whether I have entities in delete collection which are also in save collection (with isnew = true) and in such situation remove it from both collection.

How can i Achieve that ?

Best Regards, MiloszeS

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-Mar-2013 18:54:21   

Adding an entity for Deletion for it's IsNew = false, makes no sense.

So in this case the Delete routine should check in the InsertQueue of the UoW for matches. If a match is found it should delete it from the queue, otherwise, do nothing.

miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 05-Mar-2013 09:01:35   

Does it ok, if I check only the IsNew flag during the

AddForDelete(IEntity2 entityToDelete), etc... 

and in that case call the

RemoveFromUoW(IEntity2 entityToRemove) 

on UOW ?

miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 05-Mar-2013 09:29:45   

I have an issue when entity is inserted via the entitycollection. In such case the unitOfWork.GetInsertQueue () doesn't return that entity as well as RemoveFromUoW doesn't handle that properly.

Should I also iterate through all collections to save and remove this object from such collection or there is some other way to achieve that ?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Mar-2013 21:48:56   

Before calling GetInsertQueue() you need to call ConstructSaveProcessQueues() Constructs the save process queues for insert and update actions. These queues are constructed from the entities added to this UoW for save either individually or in a collection