protected override void OnModelCreating(ModelBuilder modelBuilder) { foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(s => s.GetForeignKeys())) { relationship.DeleteBehavior = DeleteBehavior.Restrict; } base.OnModelCreating(modelBuilder); }