Entity Framework and the error The DELETE statement conflicted with the REFERENCE constraint.
Posted on: February 19, 2013
Entity Framework can raise an error concerning a conflict with reference when deleting an entity. One of this error is the following one.
The DELETE statement conflicted with the REFERENCE constraint.
To solve this issue we need to delete cascade instead of a simple remove. We have seen in a previous post how to use delete in cascade with Entity Framework.
In short, you have to specify the many side to the other side (required or optional) and then specify the delete cascade statement with the true parameter.
1...HasMany(e => e.ParentDetails) .WithOptional(s => s.Parent) .WillCascadeOnDelete(true);