Closed todd-skelton closed 2 years ago
@xKloc Can you give us some insights on why you want to use owned collections for this?
The main goal was to use nested owned types and collections on my two aggregates (user and application), so I would load the entire object graph without having to chain all the includes. I tried to use two different types mapped to the same table, but I run into the same issue. I have to create a one-to-one relationship between the two types, and I can't do that because they are owned entities.
I just created some extension methods that perform all the includes for now.
@xKloc Thanks for the additional info. I'm linking this to issue #1985, which is about defining aggregate behaviors, and #2953 which is about rule-based eager loading.
I gave some thinking to this, so capturing some notes:
Rule-based eager loading that is independent of ownership/aggregates could be a good fit for this particular ask. Though in my opinion this is not as important as aggregate behaviors. I feel it is reasonable to say no to this in 3.0 and in the meantime try to improve our messaging on what ownership is and isn't for.
Having the same object instance be owned by multiple owners (as the issue is described originally) would require EF Core to deviate more from its current design/assumptions. For example, we could enable advanced mapping in which we stop altogether protecting customers from mapping multiple objects to the same table and row (currently this only works if there is a 1:1 relationship or one of the types is a query types), and trust them that they will find ways to use such mappings correctly (e.g. if they never modify two objects that map to the same row in the same unit of work, the should be fine). Incidentally this is maps to the idea of supporting multiple bounded contexts in the same model and DbContext. This also seems useful (NHibernate users have been complaining for years that EF doesn't allow this) but it doesn't feel high priority for 3.0.
This is mainly a duplicate of #2953
@AndriySvyryd @ajcvickers any update on this. I run into a similar case and I cannot define a many-to-many between two entities when the join table is a ValueObject (ownsmany)
@pantonis We aren't planning to support this as it doesn't match owned entities semantics (they can only have one owner).
I would like to have owned collections for two classes that share a table that creates a many-to-many relationship. Is there a way to map the intermediate entity as an owned collection on both entities?
Steps to reproduce
Further technical details
EF Core version: 2.2.0 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Windows 10 IDE: Visual Studio 2017 15.9.3