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

DbFunction translation considers two classes the same if they have the same name #18425

Closed
Wain123 opened this issue Oct 17, 2019 · 2 comments · Fixed by #18612
Closed

DbFunction translation considers two classes the same if they have the same name #18425

Wain123 opened this issue Oct 17, 2019 · 2 comments · Fixed by #18612
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@Wain123
Copy link

Wain123 commented Oct 17, 2019

Consider two different classes which are both called "Inner" and both have a method called "Min".

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();
		}
	}
}
var methodA = typeof(OuterA.Inner).GetMethod(nameof(OuterA.Inner.Min));
var methodB = typeof(OuterB.Inner).GetMethod(nameof(OuterB.Inner.Min));
modelBuilder.HasDbFunction(methodA).HasTranslation(parameters => new SqlFunctionExpression("TestA", methodA.ReturnType, parameters));
modelBuilder.HasDbFunction(methodB).HasTranslation(parameters => new SqlFunctionExpression("TestB", methodB.ReturnType, parameters));
ctx.TestTable.Select(z => OuterA.Inner.Min(1, 2)).First();
ctx.TestTable.Select(z => OuterB.Inner.Min(1, 2)).First();

Both of the above queries translate to

SELECT "TestB"(1.0, 2.0)
FROM "TEST_TABLE" "z"
FETCH FIRST 1 ROWS ONLY

If I rename one of the Inner classes, then the first query correctly calls TestA instead of TestB.

EF Core version: 2.2
Database provider: Microsoft.EntityFrameworkCore.Oracle
Target framework: .NET Framework 4.7
Operating system: Windows 10
IDE: Visual Studio 2017 15.8.6

@smitpatel
Copy link
Member

Repros for 3.0 in SQLServer.

@smitpatel
Copy link
Member

Root cause:
https://github.com/aspnet/EntityFrameworkCore/blob/edf5b27d5065c330cc47fd6d1fff55890a5ac54e/src/EFCore.Relational/Metadata/Internal/DbFunction.cs#L121-L124

We don't consider full type information for method's declaring type so we end up overwriting the DbFunction in the model.

@ajcvickers ajcvickers added this to the Backlog milestone Oct 18, 2019
pmiddleton added a commit to pmiddleton/EntityFramework that referenced this issue Oct 27, 2019
pmiddleton added a commit to pmiddleton/EntityFramework that referenced this issue Oct 27, 2019
pmiddleton added a commit to pmiddleton/EntityFramework that referenced this issue Oct 27, 2019
pmiddleton added a commit to pmiddleton/EntityFramework that referenced this issue Oct 27, 2019
pmiddleton added a commit to pmiddleton/EntityFramework that referenced this issue Oct 29, 2019
pmiddleton added a commit to pmiddleton/EntityFramework that referenced this issue Oct 30, 2019
pmiddleton added a commit to pmiddleton/EntityFramework that referenced this issue Oct 31, 2019
smitpatel pushed a commit to pmiddleton/EntityFramework that referenced this issue Oct 31, 2019
@smitpatel smitpatel self-assigned this Oct 31, 2019
@smitpatel smitpatel modified the milestones: Backlog, 3.1.0 Oct 31, 2019
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 31, 2019
@ajcvickers ajcvickers modified the milestones: 3.1.0-preview3, 3.1.0 Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants