fweeee,
Thanks so much for the quick response - and I assure you that your expertise far exceeds my own, having just started using C# and NetTiers.
My question is more focused on trapping and dealing with the exception, than validation. I realize that in this instance I could validate that it was OK to delete the row, and thereby avoid the exception, but that doesn't work for me as a general solution. Some of my tables have multiple complex relationships - and there are many reasons that a row deletion (or insert, or update) could fail. If I were to take the validation approach, I would have to reimplement my whole database design in validation code. That's a problem for 3 reasons:
-
Writing a boatload of validation code would take too long.
-
Conceptually, my app would then be tightly coupled with my database design, and a maintenance nightmare would result.
-
As you said, the rules around record deletion involve other records/tables in the database, and implementing a bunch of validations would create a huge performance hit (as many round-trips to the DB would be required just for the validation).
So I would prefer to let the database enforce its own referential integrity rules, and just trap what it doesn't allow. The problem is that I can't just let cryptic error error messages bubble up to the UI and blow up in the end-users' faces.
As a neophyte in both C# and NetTiers, I only have a vague conceptual understanding of how the NetTiers pieces fit together. I've read all the NetTiers documentation, but only understand about half of it because of my inexperience with C#. I can follow the execution path while debugging, but it usually leads me to a dead end. Here's an example that applies to what I'm trying to do:
I have a database table called Employees. NetTiers has generated all these things that relate my Employees table:
-
a Components project that contains EmployeesService.cs and EmployeesServiceBase.generated.cs
-
a Data project that contains EmployeesProviderBase.cs and EmployeesProviderBase.generatedCore.cs
-
a Data.SQLClient project that contains SqlEmployeesProvider.cs and SqlEmployeesProviderBase.generated.cs
-
An Entities project that contains Employees.cs, EmployeesBase.generated.cs, and IEmployees.cs
-
A web project that contains EmployeesDataSource.cs
So the questions remain; where in all these files would the best place to trap a data exception (like a foreign-key constraint), how do I trap it, and once I've trapped the exception how do I change the content of the message that gets returned to the UI (either by changing the text of the error, or marking the exception "handled" and sending sending out my own message)?
This can't be that diffucult. Isn't this something that everyone would have to do?
If anyone can help me with this, I'll be forever in your debt...
-Walt