using CMSMicroservice.Domain.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace CMSMicroservice.Infrastructure.Persistence.Configurations; public class UserInvitationConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("UserInvitations"); builder.HasQueryFilter(p => !p.IsDeleted); builder.Ignore(entity => entity.DomainEvents); builder.HasKey(entity => entity.Id); builder.Property(entity => entity.Id).UseIdentityColumn(); builder.Property(entity => entity.InviterUserId).IsRequired(); builder.Property(entity => entity.InviteeUserId).IsRequired(); builder.HasOne(entity => entity.Inviter) .WithMany() .HasForeignKey(entity => entity.InviterUserId) .OnDelete(DeleteBehavior.Restrict); builder.HasOne(entity => entity.Invitee) .WithMany() .HasForeignKey(entity => entity.InviteeUserId) .OnDelete(DeleteBehavior.Restrict); builder.HasIndex(e => e.InviteeUserId) .IsUnique() .HasDatabaseName("IX_UserInvitations_InviteeUserId"); builder.HasIndex(e => new { e.InviterUserId, e.Created }) .HasDatabaseName("IX_UserInvitations_InviterUserId_Created"); } }