Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Restrict delete solution?
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01141331
Message ID:
01142219
Views:
11
>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
Map
View

Click here to load this message in the networking platform