Created
April 30, 2019 11:22
-
-
Save bobdesaunois/d76a776eeaf8ee411b68d6678df36299 to your computer and use it in GitHub Desktop.
Disable Cascade deleting globally (Put this in OnModelCreating)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cascadeFKs = modelBuilder.Model.GetEntityTypes() | |
.SelectMany(t => t.GetForeignKeys()) | |
.Where(fk => !fk.IsOwnership && fk.DeleteBehavior == DeleteBehavior.Cascade); | |
foreach (var fk in cascadeFKs) | |
fk.DeleteBehavior = DeleteBehavior.Restrict; | |
base.OnModelCreating(modelBuilder); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment