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
|
I configured my entity to soft delete and the one-to-many relationship to be 'No Action', however, when I try to delete the entity I get the following error: "Removal behavior specifies no action, but this entity has children"
I would like to keep the foreign key intact (not null) because, technically speaking, that item is still in the database and therefore the association is valid. What is the proper way to configure my model to make this work?
Thanks! |
|
|
Hi Gild, I would suggest you probably don't want to use the RemovalAction on this relationship, because you are saying, don't allow a parent to be deleted while it has children. While it may still remain in the database, it is no longer visible to LightSpeed (because of the DeletedOn property). From a LightSpeed point of view, if you have an association referring to a non existent entity, that will cause a consistency issue and you will start seeing exceptions, which is why LightSpeed wants to null out associations when they are no longer present, so while you could technically set the association id to a value of a soft deleted entity in the database, it will make no sense for LightSpeed. In terms of the proper way to model this, do you actually need to maintain the relationship between a soft deleted entity and an active entity? If this is not the case then simply removing the RemovalAction attribute and allowing the association to be nulled out should be sufficient. You can always hold a secondary Id reference on another property if required for "archival" reasons. If you do actually need to hold reference to that relationship after a soft delete, there are two options which come to mind; You could leave the relationship unmanaged by LightSpeed, for example, set up your model so that you have the relationship's Id property visible as a standard property and then you can manually load the associated entity yourself, or set up a custom property to do this on the entity rather than relying on the automatically generated EntityHolder. Alternatively you could manage soft deletes within your application rather than through LightSpeed, but depending on how you are surfacing your queries this may be quite onerous. Jeremy |
|
|
Thanks for your reply. Based on this I am going to go back and rethink the implementation.
|
|