Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Referential Integrity
Message
 
To
14/04/2009 19:00:10
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01394872
Message ID:
01394976
Views:
51
Sam,

There may be some situations where orphan records are valid. Granted, these situations are rare, but you would not want to be limited by having this built in to a framework.

As far the situations where you do not want a delete of a parent with child records, you should definitely have triggers in your database for this, but you would also want write code to handle this as well in the business object. Having a business rule that checks all the child objects of the parent for values and return a value that says cannot be deleted would be one way to handle this. I have never done this so I am not sure if MM.NET has 'delete' business rule capability. If it does not, I would guess that you could put something into the predelete hook of the parent and return something that can be reported back to the user.

Or, possibly wire your business objects to report database level errors so that the database constraints get reported gracefully and do not blow up your app.

The latter solution is my preferred choice, but I haven't had the time or the opportunity to write this. And I only have one situation that needs this type of checking. What I did for this was to check in the interface code for the existence of a child and if so give a message that the delete cannot be done due to child records (I know its bad, but one day I will move this over to the business object).

HTH

>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform