From 39be80badac340faa05fcc4a400baf6c2d8faecd Mon Sep 17 00:00:00 2001 From: Svyatoslav Danyliv Date: Wed, 6 Oct 2021 19:16:03 +0300 Subject: [PATCH] Ported changes from version 5. Updated linq2db to 3.4.5. Bump version. --- Build/linq2db.Default.props | 2 +- Directory.Packages.props | 4 ++-- NuGet/linq2db.EntityFrameworkCore.nuspec | 2 +- .../EFCoreMetadataReader.cs | 13 ++++++++++++- .../ForMappingTestsBase.cs | 9 +++++++++ .../Models/ForMapping/ForMappingContextBase.cs | 2 ++ .../ForMapping/WithDuplicateProperties.cs | 18 ++++++++++++++++++ azure-pipelines.yml | 4 ++-- 8 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/WithDuplicateProperties.cs diff --git a/Build/linq2db.Default.props b/Build/linq2db.Default.props index 378d84c..98def4b 100644 --- a/Build/linq2db.Default.props +++ b/Build/linq2db.Default.props @@ -1,6 +1,6 @@  - 3.14.0 + 3.15.0 Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin Linq to DB diff --git a/Directory.Packages.props b/Directory.Packages.props index c68e246..5178e6e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,8 +5,8 @@ - - + + diff --git a/NuGet/linq2db.EntityFrameworkCore.nuspec b/NuGet/linq2db.EntityFrameworkCore.nuspec index 82b9daa..b82726d 100644 --- a/NuGet/linq2db.EntityFrameworkCore.nuspec +++ b/NuGet/linq2db.EntityFrameworkCore.nuspec @@ -16,7 +16,7 @@ - + diff --git a/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs b/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs index edcf64f..bf722e0 100644 --- a/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs +++ b/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs @@ -482,12 +482,23 @@ public override int GetHashCode() return found; } + private static PropertyInfo GetPropertyInfoForType(Type type, PropertyInfo propInfo) + { + if (propInfo.DeclaringType == type) + return propInfo; + + var found = type.GetProperties() + .FirstOrDefault(x => x.Module == propInfo.Module && x.MetadataToken == propInfo.MetadataToken); + + return found ?? propInfo; + } + private Sql.ExpressionAttribute? GetDbFunctionFromProperty(Type type, PropertyInfo propInfo) { if (_dependencies == null || _model == null) return null; - propInfo = (PropertyInfo?) type.GetMemberEx(propInfo) ?? propInfo; + propInfo = GetPropertyInfoForType(type, propInfo); var found = _calculatedExtensions.GetOrAdd(propInfo, mi => { diff --git a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/ForMappingTestsBase.cs b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/ForMappingTestsBase.cs index 7b24163..255f988 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/ForMappingTestsBase.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/ForMappingTestsBase.cs @@ -108,5 +108,14 @@ public virtual async Task TestUIntTable() var item = await context.UIntTable.FirstOrDefaultAsyncLinqToDB(e => e.Field64 == field64); } + [Test] + public virtual void TestAmbiguousProperties() + { + using var context = CreateContext(); + + FluentActions.Awaiting(() => context.WithDuplicateProperties.Where(x => x.Value == 1) + .ToArrayAsyncLinqToDB()).Should().NotThrow(); + } + } } diff --git a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/ForMappingContextBase.cs b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/ForMappingContextBase.cs index e8fe075..8a1deaf 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/ForMappingContextBase.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/ForMappingContextBase.cs @@ -12,5 +12,7 @@ protected ForMappingContextBase(DbContextOptions options) : base(options) public DbSet NoIdentity { get; set; } = null!; public DbSet UIntTable { get; set; } = null!; public DbSet StringTypes { get; set; } = null!; + + public DbSet WithDuplicateProperties { get; set; } = null!; } } diff --git a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/WithDuplicateProperties.cs b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/WithDuplicateProperties.cs new file mode 100644 index 0000000..99898c9 --- /dev/null +++ b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/WithDuplicateProperties.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; + +namespace LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping +{ + + public class WithDuplicatePropertiesBase + { + [Key] + public int Id { get; set; } + + public virtual string? Value { get; set; } + } + + public class WithDuplicateProperties : WithDuplicatePropertiesBase + { + public new int? Value { get; set; } + } +} diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b176c08..bbee6c3 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,8 +1,8 @@ variables: solution: 'linq2db.EFCore.sln' build_configuration: 'Release' - assemblyVersion: 3.14.0 - nugetVersion: 3.14.0 + assemblyVersion: 3.15.0 + nugetVersion: 3.15.0 artifact_nugets: 'nugets' # build on commits to important branches (master + release branches):