Skip to content

Document advanced user-defined function mapping - #5459

Draft
AndriySvyryd with Copilot wants to merge 4 commits into
mainfrom
copilot/add-missing-content-udf-mapping
Draft

Document advanced user-defined function mapping#5459
AndriySvyryd with Copilot wants to merge 4 commits into
mainfrom
copilot/add-missing-content-udf-mapping

Conversation

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

The user-defined function mapping guide omitted several registration, type-mapping, nullability, and translation APIs. It also lacked a practical built-in JSON function example.

  • Function registration

    • Document lambda-based HasDbFunction registration and default arguments.
    • Cover DbFunctionAttribute, schemas, built-in functions, and nullability metadata.
  • Store-type and JSON mapping

    • Demonstrate mapping converted CLR types to function parameter store types.
    • Add a SQL Server JSON_VALUE example and clarify value-converter limitations.
[DbFunction(Name = "JSON_VALUE", IsBuiltIn = true, IsNullable = true)]
public static string JsonValue(Dictionary<string, string> json, string path)
    => throw new NotSupportedException();

var function = modelBuilder.HasDbFunction(() => JsonValue(default, default));
function.HasStoreType("nvarchar(4000)");
function.HasParameter("json").HasStoreType("nvarchar(max)");
  • Translation behavior
    • Explain PropagatesNullability and link it to query null semantics.
    • Add cautions for constructing HasTranslation SQL expression trees.
    • Clarify that table-valued functions cannot use HasTranslation.

Copilot AI and others added 2 commits August 19, 2026 23:19
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Add missing content to user defined function mapping Document advanced user-defined function mapping Aug 19, 2026
Copilot AI requested a review from AndriySvyryd August 19, 2026 23:26
@AndriySvyryd
AndriySvyryd requested a balanced review from Copilot August 20, 2026 00:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Expands advanced EF Core user-defined function mapping documentation and samples.

Changes:

  • Adds lambda registration, schema, nullability, and translation guidance.
  • Demonstrates SQL Server JSON_VALUE with converted CLR types.
  • Clarifies HasTranslation limitations and nullability propagation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
Program.cs Adds the JSON function query.
Model.cs Adds JSON entity, conversion, and function mapping.
user-defined-function-mapping.md Documents advanced mapping APIs and behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread samples/core/Querying/UserDefinedFunctionMapping/Model.cs
Comment on lines +162 to +166
modelBuilder.Entity<JsonEntity>()
.Property(e => e.Metadata)
.HasConversion(
value => JsonSerializer.Serialize(value, (JsonSerializerOptions)null),
value => JsonSerializer.Deserialize<Dictionary<string, string>>(value, (JsonSerializerOptions)null));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Add a ValueComparer

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a ValueComparer<Dictionary<string, string>> for JsonEntity.Metadata in 10f37e1, using order-independent equality/hashing and a deep-copy snapshot.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add missing content to user defined function mapping

3 participants