Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AssemblyQualifiedName to distinguish db functions. Fix issue #18425 #18612

Merged
merged 1 commit into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))})";
smitpatel marked this conversation as resolved.
Show resolved Hide resolved

/// <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