Deleting related entities?

Posts   
 
    
edalzell
User
Posts: 44
Joined: 27-May-2008
# Posted on: 28-May-2008 21:22:02   

I have data set up like the following:

Table1: PK ID fields....

Table2 PK ID FK ParentID -> is Table1 PK Fields.....

Table3 (similar to Table2).

I want to delete a row from Table1 along with all of the related rows in Table2, Table3, etc.

What is the easiest way to do that?

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-May-2008 08:01:32   

Hi edalzell,

You need to perform the deletes by your own. LLBLGen don't perform or recommend cascade deletes atomatically, as they could be dangerous.

So I recommend you:

  1. Delete childs. If you have the childs already in memory, use adapter.DeleteEntityCollection (if you are using adapter) or yourCollection.DeleteMulti (if using SelfServicing). If the child entites aren't already in memory and you don't care, you can perform adapter.DeleteEntitiesDirectly (if using SelfServicing) or yourCollection.DelteMulti (if you are using SelfServicing).

  2. Delete the parent.

All the time you can subscribe the actions to a transaction to ensure an atomic efect. Added to that, you can add Validation to the actions, also Authorization and Auditing separately while you perform your own cascade delte.

David Elizondo | LLBLGen Support Team