Skip to content

Commit

Permalink
Use Full TypeName to distinguish db functions.
Browse files Browse the repository at this point in the history
Fix issue dotnet#18425
  • Loading branch information
pmiddleton authored and smitpatel committed Oct 31, 2019
1 parent bb01f02 commit fe0d550
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.FullName}{methodBase.Name}({string.Join(",", methodBase.GetParameters().Select(p => p.ParameterType.FullName))})";

/// <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 DbFunction_Annotation_FullName()
{
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 fe0d550

Please sign in to comment.