efcore icon indicating copy to clipboard operation
efcore copied to clipboard

ExecuteUpdate: support partial updating inside JSON documents

Open roji opened this issue 3 years ago • 7 comments
trafficstars

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.
  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.

roji avatar Aug 17 '22 21:08 roji

cc: @maumar :trollface:

smitpatel avatar Aug 17 '22 21:08 smitpatel

image

roji avatar Aug 17 '22 22:08 roji

Also consider updating nested JSON arrays when working on this, both primitive and non-primitive.

roji avatar Nov 20 '23 20:11 roji

Also make sure updating the JSON column itself works (as opposed to a partial update inside it). This will probably require extra work.

roji avatar Dec 05 '23 10:12 roji

@nasisakk your Entry type seems to be a top-level entity type (as it's directly on the context), and therefore not an actual JOSN owned entity - so this doesn't seem relevant... It's also hard to see how having [JsonIgnore] would change anything here.

Can you please open a separate issue with a runnable, minimal code sample?

roji avatar Jan 22 '24 20:01 roji

Also make sure updating the JSON column itself works (as opposed to a partial update inside it). This will probably require extra work.

Is there any workaround for this presently? (Other than not using a JSON property column)

onionhammer avatar Apr 22 '24 17:04 onionhammer

You can use ExecuteSql to perform the update you want.

roji avatar Apr 23 '24 20:04 roji