using DigitalData.UserManager.Domain.Entities; using Microsoft.EntityFrameworkCore; namespace DigitalData.UserManager.Infrastructure { public static class DbContextExtensions { public static ModelBuilder ConfigureUserManager(this ModelBuilder modelBuilder) { modelBuilder.Entity() .ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_DEL")) .ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_INS")) .ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_UPD")) .ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_UPD_LOG")); modelBuilder.Entity() .ToTable(tb => tb.HasTrigger("TBDD_GROUPS_USER_AFT_DEL")) .ToTable(tb => tb.HasTrigger("TBDD_GROUPS_USER_AFT_UPD")); modelBuilder.Entity() .ToTable(tb => tb.HasTrigger("TBDD_GROUPS_AFT_UPD")) .HasKey(group => group.Id); modelBuilder.Entity() .ToTable(tb => tb.HasTrigger("TBDD_MODULE_AFT_UPD")); modelBuilder.Entity(); modelBuilder.Entity() .ToTable(tb => tb.HasTrigger("TBDD_USER_REPRESENTATION_AFT_UPD")); return modelBuilder; } } } //TODO: DeleteBehavior.Restrict (see example comment below) is not working, probably due to table relationships. Because it tries to delete, for example, User first and then GroupOfUser. However, since GroupOfUser is not deleted while Users is deleted, the error is thrown because of the table relationship. Apply this approach after finding the solution. /* modelBuilder.Entity() .HasMany() .WithOne(gou => gou.User) .HasForeignKey(gou => gou.UserId) .OnDelete(DeleteBehavior.ClientCascade); modelBuilder.Entity() .HasMany() .WithOne(mou => mou.User) .HasForeignKey(mou => mou.UserId) .OnDelete(DeleteBehavior.ClientCascade); */