-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
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.
- 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.
- 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.
adrskw, mojtabakaviani, aradalvand, xamir82, heyjoey and 23 more