Deleting entities from collections

Posts   
 
    
obzekt
User
Posts: 60
Joined: 29-Apr-2004
# Posted on: 18-Aug-2004 17:08:48   

Say an entity Customer has an Orders collection and there is a method UpdateCustomer(CustomerEntity ce) that saves the changes of both the parent entity and its collection in one call.

Adding/Editing orders in the collection are easy to be reflected in the DB using adapter's SaveEntityCollection, but what do you suggest for deleting orders (w/o adding a different method)?

Is there a way for the client to 'flag' them as removal candidates and have the method walk through the collection, delete those flagged ones and save the rest?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 18-Aug-2004 17:57:53   

Not at the moment. (A unitofwork object is in the works at the moment as part of the runtime upgrades). What you could do is remove the entity from the collection in the grid (as it is removed from the grid as well) and add it to a collection solely for deletion purposes, then simply use DeleteEntityCollection() to delete the entities in 1 go. To make this happen in the same transaction as the saves, start a transaction first by calling StartTransaction, then call the persistence functions like save and delete.

Frans Bouma | Lead developer LLBLGen Pro
obzekt
User
Posts: 60
Joined: 29-Apr-2004
# Posted on: 19-Aug-2004 12:53:50   

I see. In other words, I have to be explicit in the method declaration about this second collection, e.g. UpdateCustomer(CustomerEntity ce, EntityCollection deletedOrders), where ce.Orders will contain the remaining order entities that are either new or edited ones.

Thanks Otis.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 20-Aug-2004 11:45:47   

obzekt wrote:

I see. In other words, I have to be explicit in the method declaration about this second collection, e.g. UpdateCustomer(CustomerEntity ce, EntityCollection deletedOrders), where ce.Orders will contain the remaining order entities that are either new or edited ones.

Yes. simple_smile

Frans Bouma | Lead developer LLBLGen Pro