33 lines
1.3 KiB
C#
33 lines
1.3 KiB
C#
using static PostFundManagement.Domain.Extensions.Constants;
|
|
|
|
namespace PostFundManagement.Domain.Configuration.Entities;
|
|
|
|
public sealed class Instrument : IEntityTypeConfiguration<Domain.Entities.Instrument>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Domain.Entities.Instrument> builder)
|
|
{
|
|
builder.ToTable(nameof(Domain.Entities.Instrument).Pluralize());
|
|
|
|
builder.HasKey(pk => pk.Id);
|
|
builder.Property(f => f.ProgrammeId).IsRequired();
|
|
builder.Property(f => f.Code).IsRequired().HasMaxLength(ShortLabelLength);
|
|
builder.Property(f => f.Name).IsRequired().HasMaxLength(LabelLength);
|
|
builder.Property(f => f.Description).IsRequired(false).HasMaxLength(TextLength);
|
|
builder.Property(f => f.Status).IsRequired().HasConversion<int>().HasDefaultValueSql("2");
|
|
builder.Property(f => f.CreatedBy).IsRequired();
|
|
builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()");
|
|
|
|
builder.HasOne(f => f.Programme)
|
|
.WithMany(f => f.Instruments)
|
|
.HasForeignKey(fk => fk.ProgrammeId)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasOne(f => f.Creator)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.CreatedBy)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
}
|
|
}
|