Reputation: 952
I've created an ASP.NET Dynamic Data Entities Web Application project with visual studio 2010. I've added a ADO.NET Entity Data Model connected to a sql Server database.
The application works fine.
I'd like to handle an exception when deleting a row in a table that has a column which is a foreign key for another table.
The exception is :
The DELETE statement conflicted with the REFERENCE constraint "FK_name". The conflict occurred in database "NAME", table "dbo.dbname", column 'Column_name'.
What I'd like to do is display a user friendly message to explain that the operation cannot be made before other rows in other table are delete.
I did some step by step debugging, but I can't find where the application does the database request, so that I can customize the code.
Thanks.
Upvotes: 2
Views: 436
Reputation: 952
I did some research and i found two options :
- I can handle the delete directly with gridview attribute OnRowDeleting
. This mean a lot of entity manipulation
- I can handle entity framework SavingChanges and check for entities on EntityState.Deleted
, then check entity navigation properties and throw an explicit message if necessary. This works with a custom validation error to show user friendly message.
Upvotes: 1