Type mapping extension point for server-side (SQL) JSON serialization
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
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': ), '$.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.
Contributor guide
Assessment
This issue has not been assessed yet.