C# Winforms, SQL Server, Entity Framework 6.
So I have two tables, Employee
and BusinessGroup
. Employee
is a foreign key in BusinessGroup
.
As part of my testing, I'm trying to delete two employees and then calling SaveChanges()
.
Naturally, it throws a DbUpdateException
which I catch and am attempting to handle.
Here's my issue: The exception seems to get thrown as soon as the first delete (attempt) takes place. What I'd like to do for my users is list ALL the records that cause a conflict (two in this case).
How can I do this?
Thanks.
Is the record you are trying to delete referenced/foreign keyed on another table? You will need to delete first the referenced record to those employees before actually deleting the employee record itself.
For example, Table A is the main table, and is referenced in Table B . You will not be able to delete a record in A unless you delete first those records in B referenced by a record in A .
So delete B records related to A record, then delete record in A .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.