-
Notifications
You must be signed in to change notification settings - Fork 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
Unable to use DbFunction in 3.0 #1747
Comments
@cwoolum - In EF Core 3.0, we removed assumption that empty schema means built-in function. So null or empty string as schema means it's default schema which would be dbo. in order to configure to use built in function it requires you to map custom translation like follows. modelBuilder
.HasDbFunction(typeof(MyContext).GetMethod(nameof(MyContext.DatePart)))
.HasTranslation(args => SqlFunctionExpression.Create("DatePart", args, typeof(int?), null)); Note that above would also fail because datepartarg will be printed as string which is not valid in SqlServer. The custom translation also need to take care of it but currently blocked by dotnet/efcore#17918 Overall for this scenario see dotnet/efcore#17268 for various ways we plan to improve this experience. |
I transferred this issue here to document the way to map to a built-in function which is different from #504 |
Also document the breaking change that null or empty schema means default schema defined in model. |
@smitpatel The breaking change note should be added ASAP |
@smitpatel Duplicate of #500? |
I am trying to use
DatePart
in EfCore 3.0 but it seems to fail due to thedbo
schema being prepended to the function name.Steps to reproduce
I always get the error
{"Cannot find either column \"dbo\" or the user-defined function or aggregate \"dbo.DatePart\", or the name is ambiguous."}
even though my definition shows an empty schema.I would expect that the
DbFunctionAttribute
would be respected and the schema would be blank. I halve also tried to use the fluent API to register with the same problemFurther technical details
EF Core version: 3.0.0-rc1
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET Core 3.0)
Operating system:
IDE: (e.g. Visual Studio 2019 16.3)
The text was updated successfully, but these errors were encountered: