Skip to content

Commit

Permalink
Moved all ef core entity configuration out of the DB Context class an…
Browse files Browse the repository at this point in the history
…d into separate EntityConfig classes for each entity in the EntityConfiguration folder
  • Loading branch information
angusmillar committed Jan 17, 2025
1 parent d0d9ed3 commit a41c2c4
Show file tree
Hide file tree
Showing 20 changed files with 546 additions and 329 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Abm.Pyro.Domain.Enums;
using Abm.Pyro.Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityConfiguration;

public class ComparatorEntityConfig : IEntityTypeConfiguration<Comparator>
{
public void Configure(EntityTypeBuilder<Comparator> builder)
{
// Comparator ---------------------------------------------------------------
builder.HasKey(x => x.SearchComparatorId);

builder.Property(x => x.SearchComparatorId).HasConversion<int>();
builder.Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength);

builder.HasData(
Enum.GetValues(typeof(SearchComparatorId))
.Cast<SearchComparatorId>()
.Select(e => new Comparator(e, e.ToString())));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Abm.Pyro.Domain.Enums;
using Abm.Pyro.Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityConfiguration;

public class HttpVerbEntityConfig : IEntityTypeConfiguration<HttpVerb>
{
public void Configure(EntityTypeBuilder<HttpVerb> builder)
{
// HttpVerb -----------------------------------------------------------------
builder.HasKey(x => x.HttpVerbId);

builder.Property(x => x.HttpVerbId).HasConversion<int>();
builder.Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength);

builder.HasData(
Enum.GetValues(typeof(HttpVerbId))
.Cast<HttpVerbId>()
.Select(e => new HttpVerb(e, e.ToString())));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Abm.Pyro.Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityConfiguration;

public class IndexDateTimeEntityConfig : IEntityTypeConfiguration<IndexDateTime>
{
public void Configure(EntityTypeBuilder<IndexDateTime> builder)
{
// IndexDateTime ---------------------------------------------------------------
builder.HasKey(x => x.IndexDateTimeId);
builder.HasIndex(x => x.LowUtc);
builder.HasIndex(x => x.HighUtc);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Abm.Pyro.Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityConfiguration;

public class IndexQuantityEntityConfig : IEntityTypeConfiguration<IndexQuantity>
{
public void Configure(
EntityTypeBuilder<IndexQuantity> builder)
{
// IndexQuantity ---------------------------------------------------------------
builder.HasKey(x => x.IndexQuantityId);
builder.HasIndex(x => x.Code);
builder.HasIndex(x => x.System);
builder.HasIndex(x => x.Quantity);
builder.HasIndex(x => x.CodeHigh);
builder.HasIndex(x => x.SystemHigh);
builder.HasIndex(x => x.QuantityHigh);

builder.Property(x => x.Code).HasMaxLength(RepositoryModelConstraints.CodeMaxLength);
builder.Property(x => x.System).HasMaxLength(RepositoryModelConstraints.StringMaxLength);
builder.Property(x => x.Quantity).HasPrecision(
RepositoryModelConstraints.QuantityPrecision,
RepositoryModelConstraints.QuantityScale);
builder.Property(x => x.Unit).HasMaxLength(RepositoryModelConstraints.CodeMaxLength);

builder.Property(x => x.CodeHigh).HasMaxLength(RepositoryModelConstraints.CodeMaxLength);
builder.Property(x => x.SystemHigh).HasMaxLength(RepositoryModelConstraints.StringMaxLength);
builder.Property(x => x.QuantityHigh).HasPrecision(
RepositoryModelConstraints.QuantityPrecision,
RepositoryModelConstraints.QuantityScale);
builder.Property(x => x.UnitHigh).HasMaxLength(RepositoryModelConstraints.CodeMaxLength);

builder
.HasOne<ResourceStore>(x => x.ResourceStore)
.WithMany(x => x.IndexQuantityList)
.HasForeignKey(x => x.ResourceStoreId)
.OnDelete(DeleteBehavior.Cascade);

builder
.HasOne<SearchParameterStore>(x => x.SearchParameterStore)
.WithMany()
.HasForeignKey(x => x.SearchParameterStoreId)
.OnDelete(DeleteBehavior.NoAction);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Abm.Pyro.Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityConfiguration;

public class IndexReferenceEntityConfig : IEntityTypeConfiguration<IndexReference>
{
public void Configure(EntityTypeBuilder<IndexReference> builder)
{
// IndexReference ---------------------------------------------------------------

builder.HasKey(x => x.IndexReferenceId);
builder.HasIndex(x => x.ResourceId);
builder.HasIndex(x => x.VersionId);
builder.HasIndex(x => x.CanonicalVersionId);

builder.Property(x => x.ResourceId)
.UseCollation(RepositoryModelConstraints.CaseSensitive)
.HasMaxLength(RepositoryModelConstraints.FhirIdMaxLength);
builder.Property(x => x.VersionId)
.HasMaxLength(RepositoryModelConstraints.FhirIdMaxLength);
builder.Property(x => x.CanonicalVersionId)
.HasMaxLength(RepositoryModelConstraints.FhirIdMaxLength);

builder
.HasOne<ResourceStore>(x => x.ResourceStore)
.WithMany(x => x.IndexReferenceList)
.HasForeignKey(x => x.ResourceStoreId)
.OnDelete(DeleteBehavior.Cascade);

builder
.HasOne<ServiceBaseUrl>(x => x.ServiceBaseUrl)
.WithMany()
.HasForeignKey(x => x.ServiceBaseUrlId)
.OnDelete(DeleteBehavior.NoAction);

builder
.HasOne<SearchParameterStore>(x => x.SearchParameterStore)
.WithMany()
.HasForeignKey(x => x.SearchParameterStoreId)
.OnDelete(DeleteBehavior.NoAction);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Abm.Pyro.Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityConfiguration;

public class IndexStringEntityConfig : IEntityTypeConfiguration<IndexString>
{
public void Configure(EntityTypeBuilder<IndexString> builder)
{
// IndexString ---------------------------------------------------------------
builder.HasKey(x => x.IndexStringId);
builder.HasIndex(x => x.Value);

builder.Property(x => x.Value);

builder
.HasOne<ResourceStore>(x => x.ResourceStore)
.WithMany(x => x.IndexStringList)
.HasForeignKey(x => x.ResourceStoreId)
.OnDelete(DeleteBehavior.Cascade);

builder
.HasOne<SearchParameterStore>(x => x.SearchParameterStore)
.WithMany()
.HasForeignKey(x => x.SearchParameterStoreId)
.OnDelete(DeleteBehavior.NoAction);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Abm.Pyro.Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityConfiguration;

public class IndexTokenEntityConfig : IEntityTypeConfiguration<IndexToken>
{
public void Configure(EntityTypeBuilder<IndexToken> builder)
{
// IndexToken ---------------------------------------------------------------
builder.HasKey(x => x.IndexTokenId);
builder.HasIndex(x => x.System);
builder.HasIndex(x => x.Code);

builder.Property(x => x.System).HasMaxLength(RepositoryModelConstraints.StringMaxLength);
builder.Property(x => x.Code).HasMaxLength(RepositoryModelConstraints.CodeMaxLength);

builder
.HasOne<ResourceStore>(x => x.ResourceStore)
.WithMany(x => x.IndexTokenList)
.HasForeignKey(x => x.ResourceStoreId)
.OnDelete(DeleteBehavior.Cascade);

builder
.HasOne<SearchParameterStore>(x => x.SearchParameterStore)
.WithMany()
.HasForeignKey(x => x.SearchParameterStoreId)
.OnDelete(DeleteBehavior.NoAction);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Abm.Pyro.Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityConfiguration;

public class IndexUriEntityConfig : IEntityTypeConfiguration<IndexUri>
{
public void Configure(EntityTypeBuilder<IndexUri> builder)
{
// IndexUri ---------------------------------------------------------------
builder.HasKey(x => x.IndexUriId);
builder.HasIndex(x => x.Uri);

builder.Property(x => x.Uri).HasMaxLength(RepositoryModelConstraints.StringMaxLength);;

builder
.HasOne<ResourceStore>(x => x.ResourceStore)
.WithMany(x => x.IndexUriList)
.HasForeignKey(x => x.ResourceStoreId)
.OnDelete(DeleteBehavior.Cascade);

builder
.HasOne<SearchParameterStore>(x => x.SearchParameterStore)
.WithMany()
.HasForeignKey(x => x.SearchParameterStoreId)
.OnDelete(DeleteBehavior.NoAction);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Abm.Pyro.Domain.Enums;
using Abm.Pyro.Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityConfiguration;

public class PublicationStatusEntityConfig : IEntityTypeConfiguration<PublicationStatus>
{
public void Configure(EntityTypeBuilder<PublicationStatus> builder)
{
// PublicationStatus --------------------------------------------------------
builder.HasKey(x => x.PublicationStatusId);

builder.Property(x => x.PublicationStatusId).HasConversion<int>();
builder.Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength);

builder.HasData(
Enum.GetValues(typeof(PublicationStatusId))
.Cast<PublicationStatusId>()
.Select(e => new PublicationStatus(e, e.ToString())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityMapping;
namespace Abm.Pyro.Repository.EntityConfiguration;

public class ResourceStoreMapping : IEntityTypeConfiguration<ResourceStore>
public class ResourceStoreEntityConfig : IEntityTypeConfiguration<ResourceStore>
{
public void Configure(EntityTypeBuilder<ResourceStore> builder)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Abm.Pyro.Domain.Enums;
using Abm.Pyro.Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityConfiguration;

public class ResourceTypeEntityConfig : IEntityTypeConfiguration<ResourceType>
{
public void Configure(EntityTypeBuilder<ResourceType> builder)
{
// ResourceType ---------------------------------------------------------------
builder.HasKey(x => x.FhirResourceType);

builder.Property(x => x.FhirResourceType).HasConversion<int>();
builder.Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.FhirResourceNameMaxLength);

builder.HasData(
Enum.GetValues(typeof(FhirResourceTypeId))
.Cast<FhirResourceTypeId>()
.Select(e => new ResourceType(e, e.ToString())));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Abm.Pyro.Domain.Enums;
using Abm.Pyro.Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityConfiguration;

public class SearchModifierCodeEntityConfig : IEntityTypeConfiguration<SearchModifierCode>
{
public void Configure(EntityTypeBuilder<SearchModifierCode> builder)
{
// SearchModifierCode ---------------------------------------------------------------
builder.HasKey(x => x.SearchModifierCodeId);

builder.Property(x => x.SearchModifierCodeId).HasConversion<int>();
builder.Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength);

builder.HasData(
Enum.GetValues(typeof(SearchModifierCodeId))
.Cast<SearchModifierCodeId>()
.Select(e => new SearchModifierCode(e, e.ToString())));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Abm.Pyro.Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityConfiguration;

public class SearchParameterStoreComparatorEntityConfig : IEntityTypeConfiguration<SearchParameterStoreComparator>
{
public void Configure(EntityTypeBuilder<SearchParameterStoreComparator> builder)
{
// SearchParameterStoreComparator ---------------------------------------------------------------
builder.HasKey(x => x.SearchParameterStoreComparatorId);
builder.HasIndex(x => x.SearchParameterStoreId);

builder.Property(x => x.SearchParameterStoreId);
builder.Property(x => x.SearchComparatorId).HasConversion<int>();
builder.HasData(Seed.SearchParameterStoreComparatorSeed.Get());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Abm.Pyro.Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Abm.Pyro.Repository.EntityConfiguration;

public class SearchParameterStoreComponentEntityConfig : IEntityTypeConfiguration<SearchParameterStoreComponent>
{
public void Configure(EntityTypeBuilder<SearchParameterStoreComponent> builder)
{
// SearchParameterStoreComponent ---------------------------------------------------------------
builder.HasKey(x => x.SearchParameterStoreComponentId);
builder.HasIndex(x => x.SearchParameterStoreId);

builder.Property(x => x.SearchParameterStoreId);
builder.Property(x => x.Definition);
builder.Property(x => x.Expression);
builder.HasData(Seed.SearchParameterStoreComponentSeed.Get());
}
}
Loading

0 comments on commit a41c2c4

Please sign in to comment.