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.Programme, Programme>]
|
||||
[EntityTypeConfiguration<ProgrammeConfiguration, Programme>]
|
||||
public class Programme : Models.Programme
|
||||
{
|
||||
public virtual User? Creator { get; set; }
|
||||
@@ -16,4 +18,41 @@ public class Programme : Models.Programme
|
||||
public virtual ICollection<Project> Projects { get; set; } = [];
|
||||
|
||||
public virtual ICollection<Award> Awards { get; set; } = [];
|
||||
}
|
||||
|
||||
public sealed class ProgrammeConfiguration : IEntityTypeConfiguration<Programme>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Programme> builder)
|
||||
{
|
||||
builder.ToTable(nameof(Programme).Pluralize());
|
||||
|
||||
builder.HasKey(pk => pk.Id);
|
||||
builder.Property(f => f.PortfolioId).IsRequired();
|
||||
builder.Property(f => f.OwnedBy).IsRequired();
|
||||
builder.Property(f => f.CreatedBy).IsRequired();
|
||||
builder.Property(f => f.UpdatedBy).IsRequired(false);
|
||||
builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()");
|
||||
builder.Property(f => f.UpdatedAt).IsRequired(false);
|
||||
builder.Property(f => f.Name).IsRequired().HasMaxLength(LabelLength);
|
||||
builder.Property(f => f.Status).IsRequired().HasConversion<int>().HasDefaultValueSql("1")
|
||||
.HasSentinel(ApprovalStatus.Pending);
|
||||
|
||||
builder.HasOne(f => f.Portfolio)
|
||||
.WithMany(f => f.Programmes)
|
||||
.HasForeignKey(fk => fk.PortfolioId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.NoAction);
|
||||
|
||||
builder.HasOne(f => f.Creator)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.CreatedBy)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.NoAction);
|
||||
|
||||
builder.HasOne(f => f.Owner)
|
||||
.WithMany()
|
||||
.IsRequired()
|
||||
.HasForeignKey(fk => fk.OwnedBy)
|
||||
.OnDelete(DeleteBehavior.NoAction);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user