5
votes

I am using EF 4.0 and am generating my Entity Model (.edmx) file from my database. I have several foreign key constraints for Cascade OnDelete, however, these are not getting set on my associations in my entity model. I click on the association and it shows End1 OnDelete: None.

When I check the Delete rules in my SQL Server 2008 database on my foreign key constraint, it says 'Cascade'.

Is there something I am missing to get the Cascade OnDelete flag to set in my entity model?

1
No, if everything is the way you described, The EDM Wizard must pick up cascading deletes from the database. One of the folk had this problem with SQLLite at stackoverflow.com/questions/2477872/…" But in your case with SQL Server 2008 it must work. Try creating a different set of tables and import it in a fresh test project and see if you can get it working there. - Morteza Manavi

1 Answers

3
votes

This answer

"I was having the same problem with SQL Server. When I tried to update mode from database, it didn't pick up the cascade rules. Note that the rules were added after the model was already created. I even tried deleting a table from the model and adding it back in. That had the same effect - no cascade rules.

However, when I created a brand new model with the same exact tables, it picked up the cascade rules. So my solution was just to delete the old model and create a new one with the same name, etc.

I guess is that there is something wrong with the update model from database process."

from this thread worked for me.