-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Make it easy to map built-in functions #17268
Comments
The problem is not related to the mapping. The issue is the sql generation is sticking the dbo schema onto the function call. Since this is a builtin function there should not be a schema attached to the call. You are correctly passing a blank schema to the DbFuction attribute. By chance are you also using the fluent api HasDbFunction and are passing in the dbo schema there, or not setting it to blank? |
In 3.0, all DbFunction mappings are assumed to be UDFs. In case you are using it to map to built-in function, you need to use HasTranslation Fluent API on IDbFunctionBuilder. |
Note from triage: The experience here could be improved by:
|
Removing milestone to discuss if we should do something for now or provide work-around to customer. modelBuilder
.HasDbFunction(typeof(MyContext).GetMethod(nameof(MyContext.DatePart)))
.HasTranslation(args => SqlFunctionExpression.Create("DatePart", args, typeof(int?), null)); |
I did about the same builder.HasDbFunction(typeof(ApplicationDbContext).GetMethod(nameof(JsonQuery)))
.HasTranslation(args =>
SqlFunctionExpression.Create("JSON_QUERY", args, typeof(string),
new StringTypeMapping("nvarchar(max)")));
but when I run a test that uses the InMemory database, it failed
|
That is because DbFunctions are relational concept. InMemory is not a relational database and it will try to execute your method which throws exception. Even if DbFunctions were core concept, how would InMemory database would know what is JSON_QUERY. |
I changed this method
on
test is passed Thanks @smitpatel |
Resolves #17268 - Introduces new API `IsBuiltIn` on DbFunctionBuilder which marks the function as built-in and we translate it accordingly.
Resolves #17268 - Introduces new API `IsBuiltIn` on DbFunctionBuilder which marks the function as built-in and we translate it accordingly. - Add `DbFunctionAttribute.IsBuiltIn` and convention to set the flag appropriately.
Resolves #17268 - Introduces new API `IsBuiltIn` on DbFunctionBuilder which marks the function as built-in and we translate it accordingly. - Add `DbFunctionAttribute.IsBuiltIn` and convention to set the flag appropriately.
Resolves #17268 - Introduces new API `IsBuiltIn` on DbFunctionBuilder which marks the function as built-in and we translate it accordingly. - Add `DbFunctionAttribute.IsBuiltIn` and convention to set the flag appropriately.
Resolves #17268 - Introduces new API `IsBuiltIn` on DbFunctionBuilder which marks the function as built-in and we translate it accordingly. - Add `DbFunctionAttribute.IsBuiltIn` and convention to set the flag appropriately.
Steps to reproduce
Further technical details
EF Core version: 3.0.100-preview7-012821 and 3.0.100-preview8-013656 and also tried with a nightly build of preview 9
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: macOS 10.13.6 (High Sierra)
IDE: JetBrains Rider 2019.2
The text was updated successfully, but these errors were encountered: