48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using PostFundManagement.Domain.Abstractions;
|
|
using static PostFundManagement.Domain.Extensions.Constants;
|
|
|
|
namespace PostFundManagement.Domain.Entities;
|
|
|
|
[EntityTypeConfiguration<OutcomeConfiguration, Outcome>]
|
|
public class Outcome : Models.Outcome, ITenantEntity
|
|
{
|
|
public virtual Tenant? Tenant { get; set; }
|
|
|
|
public virtual Beneficiary? Beneficiary { get; set; }
|
|
|
|
public virtual User? Creator { get; set; }
|
|
}
|
|
|
|
public sealed class OutcomeConfiguration : IEntityTypeConfiguration<Outcome>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Outcome> builder)
|
|
{
|
|
builder.ToTable(nameof(Outcome).Pluralize());
|
|
|
|
builder.HasKey(pk => pk.Id);
|
|
builder.Property(f => f.TenantId).IsRequired();
|
|
builder.Property(f => f.BeneficiaryId).IsRequired();
|
|
builder.Property(f => f.CreatedBy).IsRequired();
|
|
builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()");
|
|
builder.Property(f => f.Name).IsRequired().HasMaxLength(LabelLength);
|
|
builder.Property(f => f.Description).IsRequired().HasMaxLength(TextLength);
|
|
|
|
builder.HasOne(f => f.Tenant)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.TenantId)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
builder.HasOne(f => f.Beneficiary)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.BeneficiaryId)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasOne(f => f.Creator)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.CreatedBy)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
}
|
|
} |