-
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
Adding documentation for custom function mapping #2899
Conversation
5765a08
to
2dbd6a0
Compare
47daaa5
to
1441d2c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pedantic English review FTW! Feel free to ignore points if disagree.
BTW see build warnings in the CI checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add
- The HasFunction overload which takes lambda with default params to register a function
- DbFunctionAttribute and properties over that.
- Specifying a schema or marking function as built-in
- Mapping function return type or parameter to particular store type when not natively supported and scenario where it works.
- argument propagates nullability API and link to the null semantics docs.
- Ideally, we should put down the example of mapping to JSON function How to write DbFunction's translation? efcore#11295 (comment) Probably most used usecase for the UDF so far
- Mention that TVF cannot use HasTranslation API
- Few more cautions about HasTranslation API and need to understand the SQL expression tree.
f940be5
to
f8c0098
Compare
entity-framework/core/querying/user-defined-function-mapping.md
Outdated
Show resolved
Hide resolved
entity-framework/core/querying/user-defined-function-mapping.md
Outdated
Show resolved
Hide resolved
entity-framework/core/querying/user-defined-function-mapping.md
Outdated
Show resolved
Hide resolved
entity-framework/core/querying/user-defined-function-mapping.md
Outdated
Show resolved
Hide resolved
51b5370
to
1ba91a4
Compare
entity-framework/core/querying/user-defined-function-mapping.md
Outdated
Show resolved
Hide resolved
entity-framework/core/querying/user-defined-function-mapping.md
Outdated
Show resolved
Hide resolved
entity-framework/core/querying/user-defined-function-mapping.md
Outdated
Show resolved
Hide resolved
entity-framework/core/querying/user-defined-function-mapping.md
Outdated
Show resolved
Hide resolved
entity-framework/core/querying/user-defined-function-mapping.md
Outdated
Show resolved
Hide resolved
samples/core/Modeling/CustomFunctionMapping/CustomFunctionMapping.csproj
Outdated
Show resolved
Hide resolved
args.First(), | ||
args.Skip(1).First(), | ||
typeof(bool), | ||
new SqlServerBoolTypeMapping("bit")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider translating to ABS(a - b) to avoid this warning and also give example of SqlFunctionExpression translation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ended up going with slightly more complicated translation to both show the SqlFunction and custom specification of type mappings - should we add a note/caution that this is an advanced scenario?
f3d503c
to
0f8f1c6
Compare
|
||
#region HasTranslationFunctionConfiguration | ||
// 100 * ABS(first - second) / ((first + second) / 2) | ||
var doubleTypeMapping = new SqlServerDoubleTypeMapping("float"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can avoid type mapping and associated warning if you make first/second double in C# and just reuse their type mapping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we want to show people how to create the mapping themselves? like when you divide/multiply by a double constant, you would have to do it anyway no?
Fixes #500