-
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
GetDatabaseValues for owned type throws exception if the type is only used by one entity #18366
Comments
This is invalid. We don't have a way to determine the |
Thank you @smitpatel for pointing me in the right direction. I was confused because I got it to work sometimes depending on how the model was configured as showcased. Do you know the right way to get database values for an owned type so I can keep track on which properties actually been changed? |
Untested but try this var shippingAddressEntry = orderEntry.Reference("ShippingAddress").TargetEntry; |
Thanks for your suggestion! var dbValues = shippingAddressEntry.GetDatabaseValues(); |
This is related to #16186 |
Calling
EntityEntry.GetDatabaseValues()
on an owned type can raise an exception in certain circumstances.Steps to reproduce
https://github.com/coder925/EntityFramework.Docs/tree/owned-type-issue/samples/core/Modeling/OwnedEntities
Expected result: Only the changed properties of the owned entity is saved.
Actual result: An exception:
Workaround:
Uncomment code in OwnedEntityContext:
It seems if more than one Entity is owning ShipmentAddress the excpetion is not occuring.
Use case
I am receiving a detached Order entity that needs to be updated in the database. However, I am only allowed to save actual changed properties and cannot use
context.Update(order)
.Instead, I use this read-update pattern:
and for each owned type owned by Order (i.e. value objects):
Further technical details
EF Core version: 3.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.0
Operating system: Windows 10 Enterprise
IDE: Visual Studio 2019 16.3.0
The text was updated successfully, but these errors were encountered: