58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
using PostFundManagement.Domain.Abstractions;
|
|
|
|
namespace PostFundManagement.Domain.Entities;
|
|
|
|
[EntityTypeConfiguration<PortfolioConfiguration, Portfolio>]
|
|
public class Portfolio : Models.Portfolio, ITenantEntity
|
|
{
|
|
public virtual User? Creator { get; set; }
|
|
|
|
public virtual User? Owner { get; set; }
|
|
|
|
public virtual Tenant? Tenant { get; set; }
|
|
|
|
public virtual Organisation? Organisation { get; set; }
|
|
|
|
public virtual ICollection<Programme> Programmes { get; set; } = [];
|
|
}
|
|
|
|
public sealed class PortfolioConfiguration : IEntityTypeConfiguration<Portfolio>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Portfolio> builder)
|
|
{
|
|
builder.ToTable(nameof(Portfolio).Pluralize());
|
|
|
|
builder.HasKey(pk => pk.Id);
|
|
builder.Property(f => f.TenantId).IsRequired();
|
|
builder.Property(f => f.OrganisationId).IsRequired();
|
|
builder.Property(f => f.CreatedBy).IsRequired();
|
|
builder.Property(f => f.OwnedBy).IsRequired();
|
|
builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()");
|
|
builder.Property(f => f.Name).IsRequired().HasMaxLength(LabelLength);
|
|
builder.Property(f => f.Description).IsRequired(false).HasMaxLength(TextLength);
|
|
|
|
builder.HasOne(f => f.Tenant)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.TenantId)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasOne(f => f.Organisation)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.OrganisationId)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasOne(f => f.Creator)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.CreatedBy)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
builder.HasOne(f => f.Owner)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.OwnedBy)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
}
|
|
} |