General information
Category:
The Mere Mortals .NET Framework
Title:
Referential Integrity
Environment versions
Network:
Windows 2003 Server
The Mere Mortals .NET Framework provides a business object property called AutoDeleteOnParentDeleted that can be used to automatically cascade the deletion of a parent record to all related child records. But I am surprised that the framework does not seem to provide an automatic way to restrict deletion of a parent record when related child records exist. By default, AutoDeleteOnParentDeleted defaults to false which allows deletion of a parent record only and can leave orphaned child records.
I want to restrict the deletion of a parent record if any related child records exist and I want to notify the user why the deletion failed. I can think of a couple of possible ways to accomplish this but I wonder what other developers have done. I could probably set some constraints on the backend SQL tables to solve this problem, or maybe I could put code in the mmBusinessForm.HookPreDelete(DataRowView, drView) method to iterate through the RefBizObj collection of child business objects to see if any of them have records. If child records are found I could return false which would prohibit the deletion of the parent record. The problem with this solution is that only the parent DataRowView to be deleted is passed into the HookPreDelete method and I am not sure how I could reference the child records etc. from there.
It seems like restricting the deletion of the parent record when related child records exist must be a common requirement, but as far as I can see, Mere Mortals does not provide an automatic way to handle this requirement.
Sam Tenney
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only