Print Page | Close Window

WillCascadeOnDelete and deletion of loaded related entities

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4165
Printed Date: 11-Apr-2025 at 6:15pm


Topic: WillCascadeOnDelete and deletion of loaded related entities
Posted By: kdev
Subject: WillCascadeOnDelete and deletion of loaded related entities
Date Posted: 28-May-2013 at 9:42am
I have an issue when deleting an entity that have related entities (of a relationship configured to be cascade deleted) loaded.

DevForce deletes each related entity before deleting the root, if those entities were not loaded, the delation of the root entity generates a single delete command on the database.

I think that the "normal" behaviour should be to always have a single delete command when deleting an entity.
If the related entities were loaded in the manager, they should be detached from the manager and not explicitly deleted, because this cause multiple useless delete commands to be executed (with 1000+ related entities the performance quickly degrades).

Is this "by design" ?



Replies:
Posted By: sbelini
Date Posted: 28-May-2013 at 11:16am
Kdev,

That is by design.

You mentioned:
I think that the "normal" behaviour should be to always have a single delete command when deleting an entity.
If the related entities were loaded in the manager, they should be detached from the manager and not explicitly deleted, because this cause multiple useless delete commands to be executed (with 1000+ related entities the performance quickly degrades).


If the cascading delete was set on the model, but not on the DB; the save call with the single delete would fail.
For this reason, the child entities are marked for deletion as well.

You will find more information about cascading deletes at http://drc.ideablade.com/xwiki/bin/view/Documentation/save-cascaded-deletes - http://drc.ideablade.com/xwiki/bin/view/Documentation/save-cascaded-deletes



Print Page | Close Window