Skip to content

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

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.

Activity

  1. added this to the Backlog milestone on Aug 31, 2025
  2. self-assigned this
    on Aug 31, 2025
  3. modified the milestones: Backlog, 11.0.0 on Aug 31, 2025
  4. modified the milestones: 11.0.0, Backlog on Sep 9, 2025
  5. changed the title [-]Allow ExecuteUpdate updating of JSON properties to arbitrary relational expressions[/-] [+][SQLite] Allow ExecuteUpdate updating of JSON properties to arbitrary relational expressions[/+] on Sep 9, 2025
  6. roji commented on Sep 9, 2025

    @roji
    MemberAuthor

    Note that this is being done on SQL Server via #36730; keeping this issue to track SQLite support.

    SQLite is a bit trickier, since it has very little actual types - we map e.g. DateTime to a string in the database. Now, we could simply copy the source non-JSON string into the JSON document, with the assumption that it's the same (e.g. an ISO8601 string), but that's not always going to be the case. For example, M.D.Sqlite also supports mapping timestamps to ints/floats, and we don't want to just copy that into JSON documents.

    To do this correctly and reliably, this ultimately may require a type-by-type solution, checking how (and where) we can convert. Do this after #36729, which would move the server-side JSON serialization logic to the type mappings.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions