I have an Entity Framework Project for a WinForms application and the approach that I'm using is Database First. And here is my setup (I keep it as simple as possible): Sql Database Model Entity Framework Model
The problem is when I try to delete a department using the command:
context.Departamento.Remove(departamento)
It deletes every record on DepartamentoComputadora table instead of throwing an exception for the "On Delete No Action" constraint in the database.
The weird thing is that if I try to delete that department on my database it actually does not let me delete it because of the constraint.
Is any configuration that I am missing on EF to enforce the on delete no action?
It is weirder that the actual configuration of EF shows the behavior that I expect to have on the table.
Thank you in advance!
Actually, it was my fault with some issues with Git on Visual Studio. My model got broken when I committed staged changes and then even I was deleting, uninstalling EF, installing it again and recreating the model from scratch, some files were not deleted from my project folder and that was causing the problem.
The solution was pretty simple:
Creating a branch for the fix.
Deleting the Entity Data Model.
Uninstall EF and removed all left lines on app.config file referencing EF.
Installing EF again.
Creating the model again and committing changes.
Done.
Thank you very much!