Skip to content

ExecuteUpdate: support partial updating inside JSON documents #28766

@roji

Description

@roji
ctx.blogs.ExecuteUpdate(s => s.SetProperty(b => b.SomeJsonDocument.Foo, b => "foo");

Things get interesting when there are multiple updates inside the same JSON document:

ctx.blogs.ExecuteUpdate(s => s
    .SetProperty(b => b.SomeJsonDocument.Foo, b => "foo")
    .SetProperty(b => b.SomeJsonDocument.Bar, b => "bar");

We could apply the same logic we're discussing for SaveChanges:

  1. Do "least-common-denominator" to find the smallest branch containing all the properties to be updated.
    • This was discussed; unlike SaveChanges, with ExecuteUpdate the user expresses exactly what changes they want and how (it's a lower-level API). So rather than trying to guess whether a least-common-denominator is better than two point patches - a decision that EF isn't well-placed to make (it has no idea how big the properties typically are) - we'll just let the user write out the UPDATE statement they want via ExecuteUpdate.
  2. As a further optimization, nest multiple invocations (e.g. of JSON_MODIFY for SQL Server) to update the two properties; but we need to investigate and benchmark to know to what extent that makes sense and when.
    • Most databases do not allow multiple updates of the same column in the same UPDATE statements (the UPDATE setters aren't imperative instructions executed one-by-one); so nesting multiple invocations wasn't optional.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions