Deleting related entities on a recursive save

Posts   
 
    
Dusty
User
Posts: 24
Joined: 19-Feb-2008
# Posted on: 25-Feb-2008 05:49:03   

I have an entity called 'OrderHeaderEntity' that contains a related EntityCollection for the 'OrderDetailEntity' entity.

I am able to add and save child entities in the 'OrderDetailCollection' when doing a recursive save on the 'OrderHeaderEntity' object.

Is there a way to mark a child entity deleted and delete the persistent data when a recursive save is executed?

This works great!!!


OrderHeaderEntity orderHeader = new OrderHeaderEntity("123456");
orderHeader.OrderDetailCollection.Add(new OrderDetailEntity(1));
orderHeader.OrderDetailCollection.Add(new OrderDetailEntity(2));
orderHeader.OrderDetailCollection.Add(new OrderDetailEntity(3));
orderHeader.Save(true);

Would also like to do this.


OrderHeaderEntity orderHeader = new OrderHeaderEntity("123456");
orderHeader.OrderDetailCollection.RemoveAt(1);
orderHeader.Save(true);

Is it possible?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Feb-2008 10:18:35   

Removing an entity from a collection doesn't neccessarily mean it should be deleted from the database when the collection get saved.

Rather you should use a UnitOfWork to add the entity for deletion and commit the entire actions at once.

Please check the UnitOfWork in the LLBLGen manual's section "Using the generated code -> SelfServicing -> Unit of work and field data versioning"

And also check Tracking entity remove actions in the manual's section "Using the generated code -> SelfServicing -> Using the entity collection classes"