From bbc4a8290dd8bf293d3a48f46b45d4b1e0077f45 Mon Sep 17 00:00:00 2001 From: Jerrill Johnson Date: Wed, 9 Nov 2022 16:55:43 -0500 Subject: [PATCH] upgrade to .NET 7 and automapper 12. update other NuGet packages as relevant in .NET 7 target. --- Benchmarking/Benchmarking.csproj | 8 +- DataLayer/DataLayer.csproj | 12 ++- GenericServices/GenericServices.csproj | 19 +++-- .../Internal/Decoders/DecodedEntityClass.cs | 14 ++-- .../Setup/Internal/MappingProfile.cs | 3 +- ServiceLayer/ServiceLayer.csproj | 8 +- Tests/Helpers/UnitTestProfile.cs | 3 +- Tests/Tests.csproj | 75 +++++++++++-------- Tests/UnitTests/Libraries/TestAutoMapper.cs | 3 +- Tests/UnitTests/TestIssues/TestIssue60.cs | 4 +- 10 files changed, 96 insertions(+), 53 deletions(-) diff --git a/Benchmarking/Benchmarking.csproj b/Benchmarking/Benchmarking.csproj index d50535d..e571281 100644 --- a/Benchmarking/Benchmarking.csproj +++ b/Benchmarking/Benchmarking.csproj @@ -7,12 +7,12 @@ - + - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/DataLayer/DataLayer.csproj b/DataLayer/DataLayer.csproj index 9dfc30d..b449988 100644 --- a/DataLayer/DataLayer.csproj +++ b/DataLayer/DataLayer.csproj @@ -1,19 +1,25 @@  - netstandard2.1;net6.0 + netstandard2.1;net6.0;net7.0 - + - + + + + + + + diff --git a/GenericServices/GenericServices.csproj b/GenericServices/GenericServices.csproj index d62409b..1bd3606 100644 --- a/GenericServices/GenericServices.csproj +++ b/GenericServices/GenericServices.csproj @@ -1,25 +1,32 @@  - netstandard2.1;net6.0 + netstandard2.1;net6.0;net7.0 true - + - + - + - + - + + + + + + + + true 5.1.1 5.1.1 diff --git a/GenericServices/Internal/Decoders/DecodedEntityClass.cs b/GenericServices/Internal/Decoders/DecodedEntityClass.cs index 88c2af6..c0095b2 100644 --- a/GenericServices/Internal/Decoders/DecodedEntityClass.cs +++ b/GenericServices/Internal/Decoders/DecodedEntityClass.cs @@ -10,6 +10,7 @@ using GenericServices.Configuration.Internal; using Microsoft.EntityFrameworkCore; using StatusGeneric; +using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace GenericServices.Internal.Decoders { @@ -53,10 +54,13 @@ public DecodedEntityClass(Type entityType, DbContext context) return; } - // This replaces 'context.Model.FindEntityType(entityType)' because that didn't provide Owned Types - var efType = context.Model.GetEntityTypes(entityType) - //You can multiple Owned types - .FirstOrDefault(); + //// This replaces 'context.Model.FindEntityType(entityType)' because that didn't provide Owned Types + //var efType = context.Model.GetEntityTypes(entityType) + // //You can multiple Owned types + // .FirstOrDefault(); + var efEntityTypes = context.Model.GetEntityTypes(); + var efType = efEntityTypes.Where(x => x.ClrType.Name == entityType.Name) + .FirstOrDefault(); if (efType == null) { @@ -78,7 +82,7 @@ public DecodedEntityClass(Type entityType, DbContext context) return; } - var primaryKeys = efType.GetKeys().Where(x => x.IsPrimaryKey()).ToImmutableList(); + var primaryKeys = efType.GetKeys().Where(x => (x == x.DeclaringEntityType.FindPrimaryKey())).ToImmutableList(); if (primaryKeys.Count != 1) { throw new InvalidOperationException($"The class {entityType.Name} has {primaryKeys.Count} primary keys. I can't handle that."); diff --git a/GenericServices/Setup/Internal/MappingProfile.cs b/GenericServices/Setup/Internal/MappingProfile.cs index b32b204..44e8800 100644 --- a/GenericServices/Setup/Internal/MappingProfile.cs +++ b/GenericServices/Setup/Internal/MappingProfile.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using AutoMapper; +using AutoMapper.Internal; [assembly: InternalsVisibleTo("Tests")] @@ -15,7 +16,7 @@ internal class MappingProfile : Profile public MappingProfile(bool addIgnoreParts) { if (addIgnoreParts) - ForAllPropertyMaps(pm => Filter(pm.SourceMember), (pm, opt) => opt.Ignore()); + this.Internal().ForAllPropertyMaps(pm => Filter(pm.SourceMember), (pm, opt) => opt.Ignore()); } /// diff --git a/ServiceLayer/ServiceLayer.csproj b/ServiceLayer/ServiceLayer.csproj index 7f4c0e2..c66b431 100644 --- a/ServiceLayer/ServiceLayer.csproj +++ b/ServiceLayer/ServiceLayer.csproj @@ -1,7 +1,7 @@ - netstandard2.1;net6.0 + netstandard2.1;net6.0;net7.0 @@ -16,6 +16,12 @@ + + + + + + diff --git a/Tests/Helpers/UnitTestProfile.cs b/Tests/Helpers/UnitTestProfile.cs index 1903c31..e3a2676 100644 --- a/Tests/Helpers/UnitTestProfile.cs +++ b/Tests/Helpers/UnitTestProfile.cs @@ -5,6 +5,7 @@ using System.ComponentModel; using System.Reflection; using AutoMapper; +using AutoMapper.Internal; namespace Tests.Helpers { @@ -13,7 +14,7 @@ public class UnitTestProfile : Profile public UnitTestProfile(bool addIgnoreParts) { if (addIgnoreParts) - ForAllPropertyMaps(pm => Filter(pm.SourceMember), (pm, opt) => opt.Ignore()); + this.Internal().ForAllPropertyMaps(pm => Filter(pm.SourceMember), (pm, opt) => opt.Ignore()); } public void AddReadMap(Action> alterMapping = null) diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 037b2d4..a595c2b 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -1,47 +1,62 @@  - - netcoreapp3.1;net6.0 - - false - + + netcoreapp3.1;net6.0;net7.0 + false + - + - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - - - - - + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/Tests/UnitTests/Libraries/TestAutoMapper.cs b/Tests/UnitTests/Libraries/TestAutoMapper.cs index 3534c72..d53a2b9 100644 --- a/Tests/UnitTests/Libraries/TestAutoMapper.cs +++ b/Tests/UnitTests/Libraries/TestAutoMapper.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Reflection; using AutoMapper; +using AutoMapper.Internal; using AutoMapper.QueryableExtensions; using DataLayer.EfClasses; using Tests.Configs; @@ -120,7 +121,7 @@ public void TestIgnoreReadOnlyProperties() var config = new MapperConfiguration(cfg => { //see https://github.com/AutoMapper/AutoMapper/issues/2571#issuecomment-374159340 - cfg.ForAllPropertyMaps(pm => Filter(pm.SourceMember), (pm, opt) => opt.Ignore()); + cfg.Internal().ForAllPropertyMaps(pm => Filter(pm.SourceMember), (pm, opt) => opt.Ignore()); cfg.CreateMap(); }); diff --git a/Tests/UnitTests/TestIssues/TestIssue60.cs b/Tests/UnitTests/TestIssues/TestIssue60.cs index 310f962..d596126 100644 --- a/Tests/UnitTests/TestIssues/TestIssue60.cs +++ b/Tests/UnitTests/TestIssues/TestIssue60.cs @@ -6,6 +6,7 @@ using GenericServices.PublicButHidden; using GenericServices.Setup; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using TestSupport.EfHelpers; using Xunit; using Xunit.Extensions.AssertExtensions; @@ -60,7 +61,8 @@ public void TestGetEntityTypes() using var context = new Context(options); //ATTEMPT - var ownedTypes = context.Model.GetEntityTypes(typeof(Reference)); + var ownedTypes = context.Model.GetEntityTypes() + .Where(x => x.ClrType.Name == typeof(Reference).Name); //VERIFY ownedTypes.Count().ShouldEqual(2);