DeleteSelf - Grandparent, Parent, Child responsibilities.

DeleteSelf - Grandparent, Parent, Child responsibilities.

Old forum URL: forums.lhotka.net/forums/t/173.aspx


skagen00 posted on Tuesday, May 23, 2006

When I have this sort of situation:

GrandParent - ParentCollection - Parent - ChildCollection - Child

Considering deletion, a couple different scenarios:

1) Child is deleted - so it is added to the deleted list of the child collection. Come time for updating the root (GrandParent), it tells the ParentCollection to update. The Parent containing the child will have its Update called along with all the other parents.

The Parent's update, regardless of the Parent's IsDirty status, should call the child collection's Update method. The child collection's deleted list iteration will encounter the deleted child and call the DeleteSelf() of the child. The responsibility of the child's DeleteSelf() is to do what is needed to remove any persistence for the child...

2) Parent is deleted - so it is added to the deleted list of the parent collection. Come time for updating the root (GrandParent) it tells the ParentCollection to update. The ParentCollection will encounter the deleted parent and call the Parent's DeleteSelf().

---

So my question is - do you give the Parent's DeleteSelf() the responsibility for removing persistence of the child objects within its child collection? Or, within the Parent's DeleteSelf do you just iterate through the child collection and call each item's DeleteSelf()?

It seems like the responsibility might belong to the child object but performance wise you could make one stored procedure call versus one for each child. 

Hope I've articulated this correctly. Thanks.

 

Copyright (c) Marimer LLC