Skip to content

Commit

Permalink
Use AssemblyQualifiedName to distinguish db functions. Fix issue #18425
Browse files Browse the repository at this point in the history
  • Loading branch information
pmiddleton committed Oct 27, 2019
1 parent db1b4f7 commit 6ef7c9d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/EFCore.Relational/Metadata/Internal/DbFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public static IEnumerable<DbFunction> 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))})";

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
39 changes: 39 additions & 0 deletions test/EFCore.Relational.Tests/Metadata/DbFunctionMetadataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6ef7c9d

Please sign in to comment.