efcore
efcore copied to clipboard
ExecuteUpdate: support partial updating inside JSON documents
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:
- Do "least-common-denominator" to find the smallest branch containing all the properties to be updated.
- 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.
cc: @maumar :trollface:

Also consider updating nested JSON arrays when working on this, both primitive and non-primitive.
Also make sure updating the JSON column itself works (as opposed to a partial update inside it). This will probably require extra work.
@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?
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)
You can use ExecuteSql to perform the update you want.