-
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
OwnsMany with fully-defined relationship #16016
Comments
The key has to be unique, but the foreign key is not, so we can't use just the foreign key as the primary key as we do for
You can choose either option, but we show the latter one because it's both harder to configure and is better suited for the expected use of an owned type. @divega Would you like to add something else?
Yes, but you need to change
This is tracked in #12078. Using a private constructor is the best workaround for now.
|
Sorry that's a typo, I wrote the code freehand. Haven't had time to properly digest your response yet but I'll add any further questions regarding what you said then you can close the issue off. Thank you! |
@AndriySvyryd No, this is a great explanation. We should copy it into the docs. Thanks! |
Agreed! To the docs!! |
This issue is a few questions and an issue wrapped in to one, the main issue being - I don't know the difference and can't find the answer online or within the docs. You'll have to forgive me if I'm missing anything obvious, I'm fairly new to EF Core.
Let's assume I have these models:
with this entity type configuration.
Firstly a one-to-many question... What is the purpose/advantages/disadvantages of defining a complex key? From the docs "It is common to use a complex key for these type of entities incorporating the foreign key to the owner and an additional unique property that can also be in shadow state". It's completely unclear what the relationship infers and the explanation is vague at best. Specifically in an Owned one-to-many object scenario.
Secondly I want to add a navigation property to the parent, is the above example correctly defined within the context of an owned object?
Thirdly, why can't I pass the relationship object "Parent" through the constructor. This seems to throw an exception.
I've seen some posts online about using a private constructor for EFCore and a public one for your domain model (DDD concept).
E.g.
which seems to work, is this a valid solution?
Finally while I'm here; a bit of feedback on the documentation. I'm finding the documentation a bit lacking and the explanations of features are fairly loose with hardly any code examples. For example code to demonstrate using nested OwnsMany seems like an obvious one. With a bit more depth and complexity than just an object with an Id. Also I'm finding it a bit confusing with the naming of methods that are similar to older style methods within a
CollectionOwnershipBuilder
. E.g.HasOne
,HasKey
. It's not immediately obvious which methods are relevant to an Owned Relationship and which aren't.Thanks in advance EF Core wizards.
Further technical details
EF Core version: 2.2.4
Database Provider: Microsoft.EntityFrameworkCore.Sqlite
Operating system: MacOS Mojave
Built for: Xamarin.Android
IDE: Visual Studio for Mac
The text was updated successfully, but these errors were encountered: