General information
Category:
The Mere Mortals .NET Framework
>restricted deletes
Foreign key constraints when deleting a record in the primary key table.
There's two ways I see to do this:
1) Post delete action: Creating a new exception type ForeignKeyConstraintException, and handling it with some generic message "This record is used by other tables and can't be deleted."
2) Pre delete action:
a) Gathering foreign key constraints, either by
i) querying the db (over my head, in terms of time to figure out and implement,)
ii) Using a FKConstraint collection new business object property with some generalized code, or proabably better an associated class like mmBusinessRule, but myDeleteRule.
or iii) by hand coding a custom HookPreDelete() for each business object (easy to do, but would duplicate a bit of code, looking to generalize).
b) Querying for records in foriegn key tables in the HookPreDelete() event.
c) if found, cancel delete and give a more detailed error, "This record can't be deleted, as it is referred to by 21 records in the FooWidgets table."
I like the second notion, pre checking, and not throwing an exception. If someone else has figured it out already :) Am I being too precious about avoiding exceptions in this case?
Suggestions welcome, thanks.
Previous
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