Skip to content

[SQLite] Allow ExecuteUpdate updating of JSON properties to arbitrary relational expressions #36688

@roji

Description

@roji

#28766 added support for partial updating of JSON properties via ExecuteUpdate. One thing that isn't yet supported is updating such properties to arbitrary relational expressions:

_ = await ExecuteUpdateAsync(b => b.SetProperty(x => x.JsonColumn.Foo, x => x.JsonColumn.Bar + j.JsonColumn.Baz)

This also includes setting the JSON property to a regular, non-JSON colum:

_ = await ExecuteUpdateAsync(b => b.SetProperty(x => x.JsonColumn.Foo, x => x.Bar)

The reason for this limitation is that the database functions which perform partial JSON updates (e.g. JSON_MODIFY/modify on SQL Server) accept JSON types, i.e. string/int/bool; all other relational types, need to be converted to their JSON representation. While we can do that client-side for simple constants and parameters (via JsonValueReaderWriter), and can even support setting a JSON property to another JSON property (the JSON string representation can simply be copied), for anything else we need to convert the relational value to the correct JSON representation server-side.

On SQL Server, this can be done with JSON_OBJECT() as follows (implemented in #36730):

SELECT JSON_VALUE(JSON_OBJECT('v': CAST('2020-01-01 12:00' AS datetime2)), '$.v')

However, this is highly database-specific and support needs to be investigated etc.

Note that since string/int/bool are supported by database partial update functions, arbitrary expression setting does work for them.

For test coverage, see StoreTypeRelationalTestBase.TestExecuteUpdateWithinJsonToNonJsonColumn.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions