Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Wednesday, 18 September 2013

Cascading Deletions Through Code

ModelLet´s say that you do not want to use the database way, that you have a good reason to implement cascading deletions in your code only (maybe because you have no access to the database). In this case, you need to manually remove the related entities of the object under deletion.
Let´s take the Specifications´model. The predefined relations are shown in the picture, yet, cascading has not been enabled for deletions in the SQL server for the corresponding relations. Then, you need to make sure that, when removing a specification, all its SpecificationHeaders have been removed first. Of course, each and every SpecificationHeader must have been cleared off its SpecificationItems prior to its own removal.

Here is some code to do that: