Colocated entity type configurations with entities
Added tenant entities and models Modified db context
This commit is contained in:
@@ -1,7 +1,34 @@
|
||||
using static PostFundManagement.Domain.Extensions.Constants;
|
||||
|
||||
namespace PostFundManagement.Domain.Entities;
|
||||
|
||||
[EntityTypeConfiguration<Configuration.Entities.Organisation, Organisation>]
|
||||
[EntityTypeConfiguration<OrganisationConfiguration, Organisation>]
|
||||
public class Organisation : Models.Organisation
|
||||
{
|
||||
public virtual User? Creator { get; set; }
|
||||
}
|
||||
|
||||
public sealed class OrganisationConfiguration : IEntityTypeConfiguration<Organisation>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Organisation> builder)
|
||||
{
|
||||
builder.ToTable(nameof(Organisation).Pluralize());
|
||||
|
||||
builder.HasKey(pk => pk.Id);
|
||||
builder.Property(f => f.CreatedBy).IsRequired();
|
||||
builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()");
|
||||
builder.Property(f => f.RegistrationNo).IsRequired().HasMaxLength(LabelLength);
|
||||
builder.Property(f => f.Name).IsRequired().HasMaxLength(LabelLength);
|
||||
builder.Property(f => f.Email).IsRequired().HasMaxLength(LabelLength);
|
||||
builder.Property(f => f.Type).IsRequired().HasConversion<int>().HasDefaultValueSql("5")
|
||||
.HasSentinel(OrganisationType.PrivateLimitedCompany);
|
||||
builder.Property(f => f.Status).IsRequired().HasConversion<int>().HasDefaultValueSql("1")
|
||||
.HasSentinel(ActivityStatus.Active);
|
||||
|
||||
builder.HasOne(f => f.Creator)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.CreatedBy)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.NoAction);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user