DonationAlertConfiguration.cs 1.2 KB

1234567891011121314151617181920212223242526
  1. using Domain.Entities.Donations;
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.EntityFrameworkCore.Metadata.Builders;
  4. namespace Infrastructure.Persistence.Configurations.Donations;
  5. public class DonationAlertConfiguration : IEntityTypeConfiguration<DonationAlert>
  6. {
  7. public void Configure(EntityTypeBuilder<DonationAlert> builder)
  8. {
  9. builder.ToTable(nameof(DonationAlert), x => x.HasComment("후원 알림 추적"));
  10. builder.HasKey(x => x.ID);
  11. builder.HasOne(x => x.Donation).WithOne(x => x.DonationAlert).HasForeignKey<DonationAlert>(x => x.DonationID).OnDelete(DeleteBehavior.Cascade);
  12. builder.HasOne(x => x.Sponsor).WithMany().HasForeignKey(x => x.SponsorMemberID).OnDelete(DeleteBehavior.NoAction);
  13. builder.HasOne(x => x.Receiver).WithMany().HasForeignKey(x => x.ReceiverMemberID).OnDelete(DeleteBehavior.NoAction);
  14. builder.HasIndex(x => x.DonationID).IsUnique();
  15. builder.HasIndex(x => x.CorrelationID).IsUnique();
  16. builder.HasIndex(x => x.Status);
  17. builder.HasIndex(x => new { x.ReceiverMemberID, x.Status, x.CreatedAt }).IsDescending(false, false, true);
  18. builder.Property(x => x.IpAddress).HasMaxLength(50);
  19. builder.Property(x => x.UserAgent).HasMaxLength(255);
  20. }
  21. }