From 36a66a252d518d70924dc7315940025d31590cbe Mon Sep 17 00:00:00 2001 From: mikestock-nimble Date: Mon, 18 Dec 2023 09:56:35 +0000 Subject: [PATCH] renamed the properties to follow entity framework conventions --- ....cs => 20231218095513_Initial.Designer.cs} | 46 +++++++++---------- ...5_Initial.cs => 20231218095513_Initial.cs} | 0 .../Migrations/MstrContextModelSnapshot.cs | 44 +++++++++--------- .../MstrContext.cs | 14 +++--- .../Repositories/EstablishmentRepository.cs | 4 +- .../Establishment/Establishment.cs | 10 ++-- .../Helpers/DatabaseModelBuilder.cs | 4 +- 7 files changed, 61 insertions(+), 61 deletions(-) rename Dfe.Academies.Api.Infrastructure/Migrations/{20231215093335_Initial.Designer.cs => 20231218095513_Initial.Designer.cs} (98%) rename Dfe.Academies.Api.Infrastructure/Migrations/{20231215093335_Initial.cs => 20231218095513_Initial.cs} (100%) diff --git a/Dfe.Academies.Api.Infrastructure/Migrations/20231215093335_Initial.Designer.cs b/Dfe.Academies.Api.Infrastructure/Migrations/20231218095513_Initial.Designer.cs similarity index 98% rename from Dfe.Academies.Api.Infrastructure/Migrations/20231215093335_Initial.Designer.cs rename to Dfe.Academies.Api.Infrastructure/Migrations/20231218095513_Initial.Designer.cs index d893591eb..0331cbe5c 100644 --- a/Dfe.Academies.Api.Infrastructure/Migrations/20231215093335_Initial.Designer.cs +++ b/Dfe.Academies.Api.Infrastructure/Migrations/20231218095513_Initial.Designer.cs @@ -12,7 +12,7 @@ namespace Dfe.Academies.Infrastructure.Migrations { [DbContext(typeof(MstrContext))] - [Migration("20231215093335_Initial")] + [Migration("20231218095513_Initial")] partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -113,6 +113,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasColumnType("nvarchar(max)") .HasColumnName("Email"); + b.Property("EstablishmentGroupTypeId") + .HasColumnType("bigint") + .HasColumnName("FK_EstablishmentGroupType"); + b.Property("EstablishmentName") .HasColumnType("nvarchar(max)") .HasColumnName("EstablishmentName"); @@ -121,26 +125,14 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasColumnType("int") .HasColumnName("EstablishmentNumber"); - b.Property("FK_EstablishmentGroupType") - .HasColumnType("bigint") - .HasColumnName("FK_EstablishmentGroupType"); - - b.Property("FK_EstablishmentStatus") + b.Property("EstablishmentStatusId") .HasColumnType("bigint") .HasColumnName("FK_EstablishmentStatus"); - b.Property("FK_EstablishmentType") + b.Property("EstablishmentTypeId") .HasColumnType("bigint") .HasColumnName("FK_EstablishmentType"); - b.Property("FK_LocalAuthority") - .HasColumnType("bigint") - .HasColumnName("FK_LocalAuthority"); - - b.Property("FK_Region") - .HasColumnType("bigint") - .HasColumnName("FK_Region"); - b.Property("GORregion") .HasColumnType("nvarchar(max)") .HasColumnName("GORregion"); @@ -191,6 +183,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasColumnType("float") .HasColumnName("Latitude"); + b.Property("LocalAuthorityId") + .HasColumnType("bigint") + .HasColumnName("FK_LocalAuthority"); + b.Property("Longitude") .HasColumnType("float") .HasColumnName("Longitude"); @@ -321,6 +317,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasColumnType("nvarchar(max)") .HasColumnName("ReasonEstablishmentClosed"); + b.Property("RegionId") + .HasColumnType("bigint") + .HasColumnName("FK_Region"); + b.Property("ReligiousCharacter") .HasColumnType("nvarchar(max)") .HasColumnName("ReligiousCharacter"); @@ -405,12 +405,12 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("SK"); - b.HasIndex("FK_EstablishmentType"); - - b.HasIndex("FK_LocalAuthority"); + b.HasIndex("EstablishmentTypeId"); b.HasIndex("IfdPipelineSK"); + b.HasIndex("LocalAuthorityId"); + b.ToTable("EducationEstablishment", "mstr"); }); @@ -737,16 +737,16 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.HasOne("Dfe.Academies.Domain.Establishment.EstablishmentType", "EstablishmentType") .WithMany() - .HasForeignKey("FK_EstablishmentType"); - - b.HasOne("Dfe.Academies.Domain.Establishment.LocalAuthority", "LocalAuthority") - .WithMany() - .HasForeignKey("FK_LocalAuthority"); + .HasForeignKey("EstablishmentTypeId"); b.HasOne("Dfe.Academies.Domain.Establishment.IfdPipeline", "IfdPipeline") .WithMany() .HasForeignKey("IfdPipelineSK"); + b.HasOne("Dfe.Academies.Domain.Establishment.LocalAuthority", "LocalAuthority") + .WithMany() + .HasForeignKey("LocalAuthorityId"); + b.Navigation("EstablishmentType"); b.Navigation("IfdPipeline"); diff --git a/Dfe.Academies.Api.Infrastructure/Migrations/20231215093335_Initial.cs b/Dfe.Academies.Api.Infrastructure/Migrations/20231218095513_Initial.cs similarity index 100% rename from Dfe.Academies.Api.Infrastructure/Migrations/20231215093335_Initial.cs rename to Dfe.Academies.Api.Infrastructure/Migrations/20231218095513_Initial.cs diff --git a/Dfe.Academies.Api.Infrastructure/Migrations/MstrContextModelSnapshot.cs b/Dfe.Academies.Api.Infrastructure/Migrations/MstrContextModelSnapshot.cs index 8b5269e2c..f969e68c6 100644 --- a/Dfe.Academies.Api.Infrastructure/Migrations/MstrContextModelSnapshot.cs +++ b/Dfe.Academies.Api.Infrastructure/Migrations/MstrContextModelSnapshot.cs @@ -111,6 +111,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("nvarchar(max)") .HasColumnName("Email"); + b.Property("EstablishmentGroupTypeId") + .HasColumnType("bigint") + .HasColumnName("FK_EstablishmentGroupType"); + b.Property("EstablishmentName") .HasColumnType("nvarchar(max)") .HasColumnName("EstablishmentName"); @@ -119,26 +123,14 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("int") .HasColumnName("EstablishmentNumber"); - b.Property("FK_EstablishmentGroupType") - .HasColumnType("bigint") - .HasColumnName("FK_EstablishmentGroupType"); - - b.Property("FK_EstablishmentStatus") + b.Property("EstablishmentStatusId") .HasColumnType("bigint") .HasColumnName("FK_EstablishmentStatus"); - b.Property("FK_EstablishmentType") + b.Property("EstablishmentTypeId") .HasColumnType("bigint") .HasColumnName("FK_EstablishmentType"); - b.Property("FK_LocalAuthority") - .HasColumnType("bigint") - .HasColumnName("FK_LocalAuthority"); - - b.Property("FK_Region") - .HasColumnType("bigint") - .HasColumnName("FK_Region"); - b.Property("GORregion") .HasColumnType("nvarchar(max)") .HasColumnName("GORregion"); @@ -189,6 +181,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("float") .HasColumnName("Latitude"); + b.Property("LocalAuthorityId") + .HasColumnType("bigint") + .HasColumnName("FK_LocalAuthority"); + b.Property("Longitude") .HasColumnType("float") .HasColumnName("Longitude"); @@ -319,6 +315,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("nvarchar(max)") .HasColumnName("ReasonEstablishmentClosed"); + b.Property("RegionId") + .HasColumnType("bigint") + .HasColumnName("FK_Region"); + b.Property("ReligiousCharacter") .HasColumnType("nvarchar(max)") .HasColumnName("ReligiousCharacter"); @@ -403,12 +403,12 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("SK"); - b.HasIndex("FK_EstablishmentType"); - - b.HasIndex("FK_LocalAuthority"); + b.HasIndex("EstablishmentTypeId"); b.HasIndex("IfdPipelineSK"); + b.HasIndex("LocalAuthorityId"); + b.ToTable("EducationEstablishment", "mstr"); }); @@ -735,16 +735,16 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.HasOne("Dfe.Academies.Domain.Establishment.EstablishmentType", "EstablishmentType") .WithMany() - .HasForeignKey("FK_EstablishmentType"); - - b.HasOne("Dfe.Academies.Domain.Establishment.LocalAuthority", "LocalAuthority") - .WithMany() - .HasForeignKey("FK_LocalAuthority"); + .HasForeignKey("EstablishmentTypeId"); b.HasOne("Dfe.Academies.Domain.Establishment.IfdPipeline", "IfdPipeline") .WithMany() .HasForeignKey("IfdPipelineSK"); + b.HasOne("Dfe.Academies.Domain.Establishment.LocalAuthority", "LocalAuthority") + .WithMany() + .HasForeignKey("LocalAuthorityId"); + b.Navigation("EstablishmentType"); b.Navigation("IfdPipeline"); diff --git a/Dfe.Academies.Api.Infrastructure/MstrContext.cs b/Dfe.Academies.Api.Infrastructure/MstrContext.cs index 12b28c538..b124374e4 100644 --- a/Dfe.Academies.Api.Infrastructure/MstrContext.cs +++ b/Dfe.Academies.Api.Infrastructure/MstrContext.cs @@ -77,11 +77,11 @@ private void ConfigureEstablishment(EntityTypeBuilder establishme establishmentConfiguration.Property(e => e.Email).HasColumnName("Email"); establishmentConfiguration.Property(e => e.EstablishmentName).HasColumnName("EstablishmentName"); establishmentConfiguration.Property(e => e.EstablishmentNumber).HasColumnName("EstablishmentNumber"); - establishmentConfiguration.Property(e => e.FK_EstablishmentGroupType).HasColumnName("FK_EstablishmentGroupType"); - establishmentConfiguration.Property(e => e.FK_EstablishmentStatus).HasColumnName("FK_EstablishmentStatus"); - establishmentConfiguration.Property(e => e.FK_EstablishmentType).HasColumnName("FK_EstablishmentType"); - establishmentConfiguration.Property(e => e.FK_LocalAuthority).HasColumnName("FK_LocalAuthority"); - establishmentConfiguration.Property(e => e.FK_Region).HasColumnName("FK_Region"); + establishmentConfiguration.Property(e => e.EstablishmentGroupTypeId).HasColumnName("FK_EstablishmentGroupType"); + establishmentConfiguration.Property(e => e.EstablishmentStatusId).HasColumnName("FK_EstablishmentStatus"); + establishmentConfiguration.Property(e => e.EstablishmentTypeId).HasColumnName("FK_EstablishmentType"); + establishmentConfiguration.Property(e => e.LocalAuthorityId).HasColumnName("FK_LocalAuthority"); + establishmentConfiguration.Property(e => e.RegionId).HasColumnName("FK_Region"); establishmentConfiguration.Property(e => e.GORregion).HasColumnName("GORregion"); establishmentConfiguration.Property(e => e.HeadFirstName).HasColumnName("HeadFirstName"); establishmentConfiguration.Property(e => e.HeadLastName).HasColumnName("HeadLastName"); @@ -149,13 +149,13 @@ private void ConfigureEstablishment(EntityTypeBuilder establishme establishmentConfiguration .HasOne(x => x.EstablishmentType) .WithMany() - .HasForeignKey(x => x.FK_EstablishmentType) + .HasForeignKey(x => x.EstablishmentTypeId) .IsRequired(false); establishmentConfiguration .HasOne(x => x.LocalAuthority) .WithMany() - .HasForeignKey(x => x.FK_LocalAuthority) + .HasForeignKey(x => x.LocalAuthorityId) .IsRequired(false); } diff --git a/Dfe.Academies.Api.Infrastructure/Repositories/EstablishmentRepository.cs b/Dfe.Academies.Api.Infrastructure/Repositories/EstablishmentRepository.cs index f5ddc5de2..372adf361 100644 --- a/Dfe.Academies.Api.Infrastructure/Repositories/EstablishmentRepository.cs +++ b/Dfe.Academies.Api.Infrastructure/Repositories/EstablishmentRepository.cs @@ -112,8 +112,8 @@ private IQueryable BaseQuery() var result = from establishment in _context.Establishments from ifdPipeline in _context.IfdPipelines.Where(i => i.GeneralDetailsUrn == establishment.PK_GIAS_URN).DefaultIfEmpty() - from establishmentType in _context.EstablishmentTypes.Where(e => e.SK == establishment.FK_EstablishmentType).DefaultIfEmpty() - from localAuthority in _context.LocalAuthorities.Where(l => l.SK == establishment.FK_LocalAuthority).DefaultIfEmpty() + from establishmentType in _context.EstablishmentTypes.Where(e => e.SK == establishment.EstablishmentTypeId).DefaultIfEmpty() + from localAuthority in _context.LocalAuthorities.Where(l => l.SK == establishment.LocalAuthorityId).DefaultIfEmpty() select new EstablishmentQueryResult { Establishment = establishment, IfdPipeline = ifdPipeline, LocalAuthority = localAuthority, EstablishmentType = establishmentType }; return result; diff --git a/Dfe.Academies.Domain/Establishment/Establishment.cs b/Dfe.Academies.Domain/Establishment/Establishment.cs index 354524f05..19898d7b8 100644 --- a/Dfe.Academies.Domain/Establishment/Establishment.cs +++ b/Dfe.Academies.Domain/Establishment/Establishment.cs @@ -12,11 +12,11 @@ public class Establishment public string? PK_GIAS_URN { get; set; } public long? PK_CDM_ID { get; set; } public int? URN { get; set; } - public long? FK_LocalAuthority { get; set; } - public long? FK_EstablishmentType { get; set; } - public long? FK_EstablishmentGroupType { get; set; } - public long? FK_EstablishmentStatus { get; set; } - public long? FK_Region { get; set; } + public long? LocalAuthorityId { get; set; } + public long? EstablishmentTypeId { get; set; } + public long? EstablishmentGroupTypeId { get; set; } + public long? EstablishmentStatusId { get; set; } + public long? RegionId { get; set; } public int? EstablishmentNumber { get; set; } public string? EstablishmentName { get; set; } public double? Latitude { get; set; } diff --git a/TramsDataApi.Test/Helpers/DatabaseModelBuilder.cs b/TramsDataApi.Test/Helpers/DatabaseModelBuilder.cs index 8d2868fd9..cd8864790 100644 --- a/TramsDataApi.Test/Helpers/DatabaseModelBuilder.cs +++ b/TramsDataApi.Test/Helpers/DatabaseModelBuilder.cs @@ -34,8 +34,8 @@ public static Establishment BuildEstablishment() result.LocalAuthority = null; result.EstablishmentType = null; result.PK_GIAS_URN = _fixture.Create().ToString(); - result.FK_EstablishmentType = 228; - result.FK_LocalAuthority = 1; + result.EstablishmentTypeId = 228; + result.LocalAuthorityId = 1; return result; }