Reputation: 454
I'm using Entity Framework in asp.net in Visual Studio 2012. I'm just learning these stuffs. I followed this tutorial
Just created the grid and I run the web site, everything is fine except the delete operation. When I click delete it shows me an error like this:
Would somebody tell me why I'm getting this error and how to rectify this. . .
Thanks in advance
Upvotes: 1
Views: 426
Reputation: 6425
This is a pretty clear error message that a quick google would help you resolve faster.
Table CourseInstructor has a foreign key relationship with Table Person. In your EF diagram you can see this as a relationship (a line between two entities).
The database will not let you delete a Person while a CourseInstructor still has a reference to the Person, so you need to delete the relevant CourseInstructor first, ideally as part of a transaction.
If you are really struggling look up 'referential integrity' and 'referential integrity in entity framework'.
Hopefully this helps some.
Upvotes: 0
Reputation: 1059
Your answer for your question is given in your tutorial. (Applicable only if you are using the same tables and same constraints) under "Revising EntityDataSource Control Markup to Improve Performance"
The Delete button also works. Click delete for a row that has an enrollment date and the row disappears. (Rows without an enrollment date represent instructors and you may get a referential integrity error. In the next tutorial you'll filter this list to include just students.)
You are getting referential error means you haven't used cascade in delete operation so when you delete a row in person table,as the same column is referenced in student grade table. so delete won't take place. use cascade - ON DELETE CASCADE.
Upvotes: 3
Reputation: 27385
Seems as if you want to delete a person from CourseInstructor which is refereced by school.
Upvotes: 1