CoinCategoryMapConfiguration.cs 1004 B

12345678910111213141516171819202122
  1. using Domain.Entities.Crypto;
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.EntityFrameworkCore.Metadata.Builders;
  4. namespace Infrastructure.Persistence.Configurations.Crypto;
  5. public sealed class CoinCategoryMapConfiguration : IEntityTypeConfiguration<CoinCategoryMap>
  6. {
  7. public void Configure(EntityTypeBuilder<CoinCategoryMap> builder)
  8. {
  9. builder.HasIndex(x => new { x.CoinID, x.CategoryID }).IsUnique();
  10. builder.HasIndex(x => x.CategoryID);
  11. builder.HasOne(x => x.CoinCategory).WithMany(x => x.CoinCategoryMap).HasForeignKey(x => x.CategoryID).OnDelete(DeleteBehavior.Restrict);
  12. builder.ToTable(nameof(CoinCategoryMap), t => t.HasComment("코인-카테고리 연결"));
  13. builder.HasKey(x => x.ID);
  14. builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
  15. builder.Property(x => x.CoinID).IsRequired().HasComment("코인 ID");
  16. builder.Property(x => x.CategoryID).IsRequired().HasComment("카테고리 ID");
  17. }
  18. }