using Domain.Entities.Stocks; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Infrastructure.Persistence.Configurations.Stocks; public sealed class StockConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.HasIndex(x => x.Code).IsUnique(); builder.HasIndex(x => x.ISIN).IsUnique().HasFilter("[ISIN] IS NOT NULL"); builder.HasIndex(x => new { x.Market, x.IsActive }); builder.HasIndex(x => x.Name); builder.HasIndex(x => x.CorpCode); builder.ToTable(nameof(Stock), t => t.HasComment("종목 마스터 (KRX 상장종목)")); builder.HasKey(x => x.ID); builder.Property(x => x.Code).HasMaxLength(6).IsFixedLength().IsRequired().HasComment("단축코드"); builder.Property(x => x.ISIN).HasMaxLength(12).IsFixedLength().HasComment("표준코드"); builder.Property(x => x.Name).HasMaxLength(100).IsRequired(); builder.Property(x => x.EnglishName).HasMaxLength(200); builder.Property(x => x.Market).HasConversion().IsRequired().HasComment("시장 구분 (1=KOSPI, 2=KOSDAQ, 3=KONEX)"); builder.Property(x => x.TradingStatus).HasConversion().IsRequired().HasComment("거래 상태 (0=정상, 1=거래정지, 2=관리종목)"); builder.Property(x => x.CorpCode).HasMaxLength(8).IsFixedLength().HasComment("DART 고유번호"); builder.Property(x => x.SectorName).HasMaxLength(100); builder.Property(x => x.LastChangeRate).HasPrecision(7, 2); } }