Created
April 30, 2019 11:23
-
-
Save bobdesaunois/9610681c11819184ac1c62492f1b7ff6 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