DonorChannelStatsConfiguration.cs 1.5 KB

123456789101112131415161718192021222324252627
  1. using Domain.Entities.Donations;
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.EntityFrameworkCore.Metadata.Builders;
  4. namespace Infrastructure.Persistence.Configurations.Donations;
  5. public sealed class DonorChannelStatsConfiguration : IEntityTypeConfiguration<DonorChannelStats>
  6. {
  7. public void Configure(EntityTypeBuilder<DonorChannelStats> builder)
  8. {
  9. builder.HasOne(x => x.Donor).WithMany().HasForeignKey(x => x.DonorMemberID).OnDelete(DeleteBehavior.NoAction);
  10. builder.HasOne(x => x.Channel).WithMany().HasForeignKey(x => x.ChannelID).OnDelete(DeleteBehavior.NoAction);
  11. builder.ToTable(nameof(DonorChannelStats), x => x.HasComment("후원자×채널 누적 후원 (칭호 획득 판정용)"));
  12. builder.HasKey(x => new { x.DonorMemberID, x.ChannelID });
  13. builder.Property(x => x.DonorMemberID).HasComment("후원자 회원 ID");
  14. builder.Property(x => x.ChannelID).HasComment("채널 ID");
  15. builder.Property(x => x.CumulativeAmount).IsRequired().HasComment("누적 후원 금액");
  16. builder.Property(x => x.DonationCount).IsRequired().HasComment("후원 횟수");
  17. builder.Property(x => x.FirstDonatedAt).HasComment("첫 후원 일시");
  18. builder.Property(x => x.LastDonatedAt).HasComment("마지막 후원 일시");
  19. builder.Property(x => x.UpdatedAt).HasComment("수정 일시");
  20. builder.Property(x => x.CreatedAt).IsRequired().HasComment("생성 일시");
  21. builder.HasIndex(x => new { x.ChannelID, x.CumulativeAmount }).IsDescending(false, true);
  22. }
  23. }