PaperPositionConfiguration.cs 1.3 KB

12345678910111213141516171819202122232425
  1. using Domain.Entities.Paper;
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.EntityFrameworkCore.Metadata.Builders;
  4. namespace Infrastructure.Persistence.Configurations.Paper;
  5. public sealed class PaperPositionConfiguration : IEntityTypeConfiguration<PaperPosition>
  6. {
  7. public void Configure(EntityTypeBuilder<PaperPosition> builder)
  8. {
  9. builder.HasOne(x => x.Account).WithMany().HasForeignKey(x => x.AccountID).OnDelete(DeleteBehavior.Cascade);
  10. builder.HasIndex(x => new { x.AccountID, x.StockCode }).IsUnique();
  11. builder.ToTable(nameof(PaperPosition), t => t.HasComment("모의투자 보유 포지션"));
  12. builder.HasKey(x => x.ID);
  13. builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
  14. builder.Property(x => x.AccountID).IsRequired().HasComment("계좌 ID");
  15. builder.Property(x => x.StockCode).HasMaxLength(6).IsFixedLength().IsRequired().HasComment("단축코드");
  16. builder.Property(x => x.Quantity).IsRequired().HasComment("보유 수량");
  17. builder.Property(x => x.ReservedQuantity).IsRequired().HasComment("매도 예약 수량");
  18. builder.Property(x => x.AvgPrice).HasPrecision(18, 4).IsRequired().HasComment("평균 단가");
  19. builder.Property(x => x.UpdatedAt).IsRequired();
  20. builder.Property(x => x.RowVersion).IsRowVersion();
  21. }
  22. }