Colocated entity type configurations with entities
Added tenant entities and models Modified db context
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using static PostFundManagement.Domain.Extensions.Constants;
|
||||
|
||||
namespace PostFundManagement.Domain.Entities;
|
||||
|
||||
[EntityTypeConfiguration<Configuration.Entities.Portfolio, Portfolio>]
|
||||
[EntityTypeConfiguration<PortfolioConfiguration, Portfolio>]
|
||||
public class Portfolio : Models.Portfolio
|
||||
{
|
||||
public virtual User? Creator { get; set; }
|
||||
@@ -11,3 +13,37 @@ public class Portfolio : Models.Portfolio
|
||||
|
||||
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.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.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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user