Last active
May 21, 2024 15:15
-
-
Save umair-me/e9d8978642c90acdd68cc2c3baa44eb4 to your computer and use it in GitHub Desktop.
EF Core Set all foreign keys to delete restrict
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
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys())) | |
relationship.DeleteBehavior = DeleteBehavior.Restrict; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment