After reading Foreign Keys in the Entity Framework I tried adding a Foreign Key relationship to an EF 5 Code First application (the app uses Independent Associations to date).
I noticed that the generated DDL includes a cascade delete. This is the opposite of the behavior with Independent Associations.
Given that a Foreign Key relationship is created in EF Code First by adding an int property named according to the convention ClassnameId, is it possible to have a non-cascading delete? If so, what value would be assigned to ClassnameId to disassociate the related object without deleting it from the database?
If you explicitly declare a foreign key, that is non nullable, EF will assume that you want a cascading delete.
You can either make the Foreign key nullable:
Or you can use fluent notations in your
OnModelCreating