Skip to content

Type mapping extension point for server-side (SQL) JSON serialization #36729

Open

Description

@roji

EF 10 introduced ExecuteUpdate support for JSON, which allows partially updating properties without JSON documents; this happens fully on the server-side, with no client-side JSON serialization (as in SaveChanges).

How exactly an arbitrary relational value is converted to JSON - in SQL - is a non-trivial thing that varies across databases:

  • In EF 10 for SQL Server, we're generating JSON_VALUE(JSON_OBJECT('v': <RELATIONAL VALUE>), '$.v')) to construct a JSON object (server-side) containing the relational value, and then extract it out as JSON.
  • However, geography and geometry are unsupported by JSON_OBJECT ("user-defined types"), and so we special-case them and use ST_AsText instead.
  • SQLite needs special handling to convert 1 and 0 to JSON true/false.

All this database-specific and type-specific logic currently lives in RelationalQueryableMethodTranslatingExpressionVisitorTrySerializeScalarToJson, overridden by each provider. However, we should consider moving that to a type mapping API instead. This would also allow for EF plugins to easily add their own logic, if necessary.

Activity

  1. added this to the Backlog milestone on Sep 9, 2025
  2. self-assigned this
    on Sep 9, 2025
  3. added theissue type on Sep 9, 2025
  4. AndriySvyryd commented on Sep 9, 2025

    @AndriySvyryd
    Member

    Related to #38036

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions