From 6ef7c9d36ffcde0456f567079411d3148594496d Mon Sep 17 00:00:00 2001 From: Paul Middleton Date: Sun, 27 Oct 2019 11:54:02 -0500 Subject: [PATCH] Use AssemblyQualifiedName to distinguish db functions. Fix issue #18425 --- .../Metadata/Internal/DbFunction.cs | 3 +- .../Metadata/DbFunctionMetadataTests.cs | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/EFCore.Relational/Metadata/Internal/DbFunction.cs b/src/EFCore.Relational/Metadata/Internal/DbFunction.cs index 0a169e3c446..20076d2471b 100644 --- a/src/EFCore.Relational/Metadata/Internal/DbFunction.cs +++ b/src/EFCore.Relational/Metadata/Internal/DbFunction.cs @@ -121,7 +121,8 @@ public static IEnumerable GetDbFunctions([NotNull] Model model) private static string BuildAnnotationName(MethodBase methodBase) => // ReSharper disable once AssignNullToNotNullAttribute - $"{RelationalAnnotationNames.DbFunction}{methodBase.DeclaringType.ShortDisplayName()}{methodBase.Name}({string.Join(",", methodBase.GetParameters().Select(p => p.ParameterType.Name))})"; + // ReSharper disable once PossibleNullReferenceException + $"{RelationalAnnotationNames.DbFunction}{methodBase.DeclaringType.AssemblyQualifiedName}{methodBase.Name}({string.Join(",", methodBase.GetParameters().Select(p => p.ParameterType.Name))})"; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/test/EFCore.Relational.Tests/Metadata/DbFunctionMetadataTests.cs b/test/EFCore.Relational.Tests/Metadata/DbFunctionMetadataTests.cs index d6bbb24be8c..cdd90593cfe 100644 --- a/test/EFCore.Relational.Tests/Metadata/DbFunctionMetadataTests.cs +++ b/test/EFCore.Relational.Tests/Metadata/DbFunctionMetadataTests.cs @@ -213,6 +213,27 @@ public static int MethodI() } } + public static class OuterA + { + public static class Inner + { + public static decimal? Min(decimal? a, decimal? b) + { + throw new Exception(); + } + } + } + public static class OuterB + { + public static class Inner + { + public static decimal? Min(decimal? a, decimal? b) + { + throw new Exception(); + } + } + } + [ConditionalFact] public virtual void DbFunctions_with_duplicate_names_and_parameters_on_different_types_dont_collide() { @@ -601,6 +622,24 @@ public void DbParameters_StoreType() Assert.Equal(typeof(int), dbFunc.Parameters[1].ClrType); } + [ConditionalFact] + public void DbParameters_AssemblyQualifiedName() + { + var modelBuilder = GetModelBuilder(); + + var methodA = typeof(OuterA.Inner).GetMethod(nameof(OuterA.Inner.Min)); + var methodB = typeof(OuterB.Inner).GetMethod(nameof(OuterB.Inner.Min)); + + var funcA = modelBuilder.HasDbFunction(methodA); + var funcB = modelBuilder.HasDbFunction(methodB); + + funcA.HasName("MinA"); + + Assert.Equal("MinA", funcA.Metadata.Name); + Assert.Equal("Min", funcB.Metadata.Name); + Assert.NotEqual(funcA.Metadata.Name, funcB.Metadata.Name); + } + private ModelBuilder GetModelBuilder(DbContext dbContext = null) { var conventionSet = new ConventionSet();