Cascading Deletes

Posts   
 
    
jerz
User
Posts: 3
Joined: 26-Mar-2008
# Posted on: 02-Apr-2008 12:32:59   

Basically, I'm not interested in adding the cascading delete to sql server so I want to use the DeleteMulti..() methods on an entity for all it's related data.

Now, ideally I want to do this in a transaction, but before I do that I just wanted to check something first.

It seems to me that in order to use a transaction (in self servicing mode) you need to add the entity to the transaction?

Then you can perform operations on the entity using that transaction.

Now, if I want to call something like

customer.getMultiOrders.deleteMulti() customer.delete()

Does this mean that the CustomerEntity and it's OrderEntities are fetched from the database? It seems to me to be a pointless use of bandwidth and processing? Am I missing something?

Also, I assume that in this instance I only have to add the CustomerEntity to a transaction and everything relating to that entity will be executed within that transaction?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Apr-2008 12:50:24   

If you don't want to load data, use DeleteMulti on an empty collection specifying a filter.

DeleteMulti(IPredicate) Deletes from the persistent storage all entities of the type this collection is for which match with the specified filter, formulated in the predicate or predicate expression definition.

This can also be used to delete a single entity (filtering on the PK). Use them in a UnitOfWork object for a transactional execution.

gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 03-Apr-2008 15:39:54   

Hi,

The only thing to keep in mind is that any "OnDelete" code on your entities is not executed when you delete directly on the database. I think it's also the same that no Authorization, Validation, Auditing is executed, but not 100% about that.

Gab.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 03-Apr-2008 15:46:54   

That's right.