dotnet / dotnet/efcore

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

Open
#36,729 1 comment 1 reaction 0 assignees View on GitHub
area-bulkupdate area-json area-query consider-for-next-release
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.