-
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 same owned entity instance to be shared by many owners #12345
Comments
@elfrico Sharing owned entity type instances is not supported; I have created an issue to document this: dotnet/EntityFramework.Docs#764 Triage: we will attempt to make the exception message better in this case since there is some expectation that owned types will act like value objects, which is true in some ways, but in general not the best way to view them conceptually. |
Another note from triage: when looking at this consider how feasible it would be to attempt to support this. |
@ajcvickers Thanks for investigation and clarification |
Interesting looks like for value objects you would have to have the status be on the relationship instead of the entity, else you would have to copy the value object for each relationship. |
Attach same error #10578 |
When I use |
Closing as this is no longer something we intend to implement. |
How should we be implementing ValueObjects with Entity Framework Core? I am using 3.1.5 and currently I am unable to support a DDD model with ValueObjects as I cannot share instances of value objects as owned entities between many owners. This is a basic concept, I think. I for example have an object ControlPanel with a value object ControlPanelNodeId. I want to add a Zone to my ControlPanel. The Zone also has a ControlPanelNodeId property. When creating a Zone on the ControlPanel, the ControlPanelNodeId is populated with the value of the NodeId from the ControlPanel. This means the Control Panel and the new Zone are sharing the same ControlPanelNodeId value object. However, I encounter an error as the owned entity ControlPanelNodeID cannot be shared. Please can you point me to documentation which shows me how to implement ValueObjects for a DDD model? |
Value object support will be implemented by #13947 |
Thank you @AndriySvyryd. For now I am having to implement a method on my value objects which allows me to clone them, effectively creating a new instance with the exact same value. So when I assign a value object to a property on another aggregate, within the backing state that I have on an aggregate I call the .Clone() method in the property setter. This allows me to get around the issue where EF Core is tracking the same instance by assigning an shadow ID to it. Hopefully I can engineer this out when a better solution is offered either through #13947 or #9906? |
@PTatsky Yes, those two will likely be implemented together |
I know this is closed, but is there any solution besides creating a clone method? I'm sorry, but coming from NH to EF is really a huge pain because EF seems to only understand tables... |
DDD style value object cannot be reused. Exception is thrown on context.SaveChanges().
Steps to reproduce
Further technical details
EF Core version: 2.1.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Win 10
IDE: Visual Studio 2017 15.7.3
The text was updated successfully, but these errors were encountered: