This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi Guys, I'm got a problem with the cascading delete option maybe I'm just not understanding is correctly. So I've created a repo project that you can have a look at it and let me know where I'm going wrong. Kind regards, Johan |
|
|
Hi Johan, You are not actually performing any delete's in the repro, rather you are setting the relationship between an option and its model to null (which is reflected by an UPDATE of the same if you have a look at the emitted SQL). Since no objects are getting removed, there is no cascade. If you are intending to actually remove the option, just call unit.Remove(option) rather than removing it from the model.Options collection, the Remove call will also cause it to be unwired from that collection :)
Jeremy |
|
|
The Model.Options association is nullable. Therefore, when you remove an Option out of the a model.Options collection, that Option is not deleted: instead, it is merely removed from the collection, and its ModelId is set to null. Consequently, there is no delete to cascade down to the Option.Results collection: the Results remain associated with the free-floating Option. (As it happens, your Option.Results association is also nullable, so even if you did delete the Option, the Results would similarly be disassociated rather than deleted.) To ensure that everything gets deleted, either: * Explicitly remove child items from the unit of work (of course, this will work only if you load the child items); or * Make the associations non-nullable; or * Set the Is Dependent option on the associations. |
|
|
Thank you, I've found the problem I had to mark all the associations non-nullable and set the IsDependent option on all the associations and now it work. Thanks for the feedback just need to get the project done now ;) Cheers |
|