StockDailyPriceConfiguration.cs 980 B

1234567891011121314151617181920
  1. using Domain.Entities.Stocks;
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.EntityFrameworkCore.Metadata.Builders;
  4. namespace Infrastructure.Persistence.Configurations.Stocks;
  5. public sealed class StockDailyPriceConfiguration : IEntityTypeConfiguration<StockDailyPrice>
  6. {
  7. public void Configure(EntityTypeBuilder<StockDailyPrice> builder)
  8. {
  9. builder.HasOne(x => x.Stock).WithMany().HasForeignKey(x => x.StockID).OnDelete(DeleteBehavior.NoAction);
  10. builder.HasIndex(x => new { x.StockID, x.TradingDate }).IsUnique();
  11. builder.HasIndex(x => new { x.TradingDate, x.ChangeRate }).IsDescending(false, true);
  12. builder.HasIndex(x => new { x.TradingDate, x.TradingValue }).IsDescending(false, true);
  13. builder.ToTable(nameof(StockDailyPrice), t => t.HasComment("T+1 일별 마감 시세 (금융위 API)"));
  14. builder.HasKey(x => x.ID);
  15. builder.Property(x => x.ChangeRate).HasPrecision(7, 2).HasComment("등락률 %");
  16. }
  17. }