Colocated entity type configurations with entities
Added tenant entities and models Modified db context
This commit is contained in:
@@ -1,9 +1,41 @@
|
||||
using static PostFundManagement.Domain.Extensions.Constants;
|
||||
|
||||
namespace PostFundManagement.Domain.Entities;
|
||||
|
||||
[EntityTypeConfiguration<Configuration.Entities.Indicator, Indicator>]
|
||||
[EntityTypeConfiguration<IndicatorConfiguration, Indicator>]
|
||||
public class Indicator : Models.Indicator
|
||||
{
|
||||
public virtual Project? Project { get; set; }
|
||||
|
||||
public virtual User? Creator { get; set; }
|
||||
}
|
||||
|
||||
public sealed class IndicatorConfiguration : IEntityTypeConfiguration<Indicator>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Indicator> builder)
|
||||
{
|
||||
builder.ToTable(nameof(Indicator).Pluralize());
|
||||
|
||||
builder.HasKey(pk => pk.Id);
|
||||
builder.Property(f => f.ProjectId).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.UnitOfMeasure).IsRequired().HasConversion<int>().HasDefaultValueSql("2");
|
||||
builder.Property(f => f.BaselineAmount).IsRequired().HasPrecision(18, 2);
|
||||
builder.Property(f => f.TargetAmount).IsRequired().HasPrecision(18, 2);
|
||||
builder.Property(f => f.ActualAmount).IsRequired().HasPrecision(18, 2);
|
||||
|
||||
builder.HasOne(f => f.Project)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.ProjectId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(f => f.Creator)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.CreatedBy)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.NoAction);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user