protected override void OnModelCreating(ModelBuilder builder) { // Needed for Identity models configuration base.OnModelCreating(builder); ConfigureUserIdentityRelations(builder); EntityIndexesConfiguration.Configure(builder); var entityTypes = builder.Model.GetEntityTypes().ToList(); // Set global query filter for not deleted entities only var deletableEntityTypes = entityTypes .Where(et => et.ClrType != null && typeof(IDeletableEntity).IsAssignableFrom(et.ClrType)); foreach (var deletableEntityType in deletableEntityTypes) { var method = SetIsDeletedQueryFilterMethod.MakeGenericMethod(deletableEntityType.ClrType); method.Invoke(null, new object[] { builder }); } // Disable cascade delete var foreignKeys = entityTypes .SelectMany(e => e.GetForeignKeys().Where(f => f.DeleteBehavior == DeleteBehavior.Cascade)); foreach (var foreignKey in foreignKeys) { foreignKey.DeleteBehavior = DeleteBehavior.Restrict; } }
protected override void OnModelCreating(ModelBuilder builder) { // Needed for Identity models configuration base.OnModelCreating(builder); ConfigureUserIdentityRelations(builder); EntityIndexesConfiguration.Configure(builder); var entityTypes = builder.Model.GetEntityTypes().ToList(); // Disable cascade delete var foreignKeys = entityTypes .SelectMany(e => e.GetForeignKeys().Where(f => f.DeleteBehavior == DeleteBehavior.Cascade)); foreach (var foreignKey in foreignKeys) { foreignKey.DeleteBehavior = DeleteBehavior.Restrict; } }