-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow passing complex type instances to ExecuteUpdate
#32058
Comments
ExecuteUpdate doesn't (currently) support passing an entire owned object; it requires you reference properties that map to columns in the database. Simply decompose the owned instance as follows: db.Users
.Where(u => u.Id == userId)
.ExecuteUpdate(b => b
.SetProperty(u => u.FullName.FirstName, someFullNameObj.FirstName)
.SetProperty(u => u.FullName.LastName, someFullNameObj.LastName)
); |
@roji Thanks for the quick response! And also: Would EF8's complex types support this? Or do they have the same problem? |
@xamir82 I do think we should support this, but given that you can decompose to individual property setters this would simply be a bit of sugar, nothing more. So I'd say this is quite low-priority compared to our other issues. Complex types will have the same limitation, yes. |
ExecuteUpdate
not working with owned type propertyExecuteUpdate
Turns out this is not merely a nice-to-have as has been implied here, there would actually be no way to use @roji Don't you think it would make sense to add the |
I don't think there's anything special regarding collections here: just like you can't replace a standalone object within JSON (that's not in a collection), you can't replace an object that's within a collection. And once #28766 is implemented, you could modify all the properties within an object in a collection, in the same way you would for an object not within a collection. So unless I'm mistaken, passing in an entire entity instance still effectively be a nicer alternative to listing out the properties one-by-one - or am I missing something? |
@roji Well, how would you do the equivalent of the following, even if #28766 was implemented? db.Products.ExecuteUpdate(b => b.SetProperty(p => p.Traits, newTraits)); (where |
That's not an entity instance - it's a list of instances. We can indeed track that here as part of this issue, though it would likely require it's own specific work... In any case, I've put the consider-for-current-release label on this. |
I guess I assumed that this represents basically the same underlying problem (or at least that they're related). So yes, I think it does make sense to track it here. @xamir82 perhaps you could adjust the title of the issue a little bit to reflect this more clearly? Thanks.
Thank you very much! |
ExecuteUpdate
ExecuteUpdate
roji beat me to it :P |
ExecuteUpdate
ExecuteUpdate
ExecuteUpdate
ExecuteUpdate
I implemented updating complex types in #32499 (that's the "sugar" mentioned above). The EF 8.0 support for complex types doesn't support collections; we hope to make this possible for 9.0 via JSON mapping of complex types. When this happens, using ExecuteUpdate (and possibly ExecuteDelete) to make changes inside JSON documented is tracked by #28766. |
Thank you @roji
When that happens, will support for using |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
No, it does not. Just like you cannot assign a customer's owned shipping address to be their billing address (that would mean the same entity instance is referenced twice), I don't think it makes sense to allow this via ExecuteUpdate. This is exactly the kind of mismatch that makes the new complex types better for modeling containment/document structures than the current owned entity support. Hopefully everything works out for complex types in 9.0 and you'll be able to use them to model JSON etc.
That's indeed something that should be supported as well - I'll add a note on #28766. |
Makes sense. Thanks! |
Note from triage: updating owned entity type instances should be covered by #29654, unless that turns out to be prohibitively expensive. |
Reopening as #32499 hasn't been merged yet (waiting to be reviewed). Regardless, @ajcvickers I don't think #29654 is quite the right issue here... I think we're discussing two possibly different capabilities:
If that all makes sense, then I think we're missing an issue for option (1) applied to entity types. |
@ajcvickers opened #32719 with some design thoughts... it's a bit more complicated than it looks :) (surprise!) |
Imagine this model:
Inserting a
User
with by assigning aFullName
object to theFullName
property works:But doing the same with
ExecuteUpdate
doesn't work:It throws an exception along these lines:
This is an unexpected asymmetry between how insert and update work, I think most people would intuitively expect the
ExecuteUpdate
example to work just fine, it's a bit surprising, a weird limitation.Let me know if there's an existing issue for this.
The text was updated successfully, but these errors were encountered: