Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rc1 added "cascade delete" to all of my relationships #3851

Closed
joshmouch opened this issue Nov 23, 2015 · 3 comments
Closed

Rc1 added "cascade delete" to all of my relationships #3851

joshmouch opened this issue Nov 23, 2015 · 3 comments

Comments

@joshmouch
Copy link

After upgrading to RC1 from Beta8, when I generate a new migration, it wants to drop all of my FK's and recreate them with a cascade delete.
How can I disable this as the default behavior?

@smitpatel
Copy link
Contributor

@joshmouch - Migration drops and recreates all FKs due #3751
By conventions EF will set cascade delete for all the require foreign keys. If you don't want "cascade delete" then you should make your foreign key not required. You can read about it in the docs at http://ef.readthedocs.org/en/latest/modeling/relationships.html

@rowanmiller
Copy link
Contributor

If you want to change the delete behavior, then you can use this code in OnModelCreating(...) to bulk set it for all relationships in your model.

foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
{
    relationship.DeleteBehavior = DeleteBehavior.Restrict;
}

@joshmouch
Copy link
Author

@rowanmiller Thanks for the prompt reply! The problem with that default behavior is that somehow now I have cyclical deletes. I'll run the code you gave me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants