Skip to content

Instantly share code, notes, and snippets.

@umair-me
Last active May 21, 2024 15:15
Show Gist options
  • Save umair-me/e9d8978642c90acdd68cc2c3baa44eb4 to your computer and use it in GitHub Desktop.
Save umair-me/e9d8978642c90acdd68cc2c3baa44eb4 to your computer and use it in GitHub Desktop.
EF Core Set all foreign keys to delete restrict
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