-
Notifications
You must be signed in to change notification settings - Fork 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
a join entity instead of a shadow foreign key #3606
Comments
@yecril71pl This tracked by dotnet/efcore#3864. The workaround for now is to create a private collection navigation, or even make it a field. |
My pain point is not visibility but the fact that I would have to add a navigation field in C for every superior that has C as a dependent. The only acceptable workaround is using an explicit association class. However, the natural candidate, a KeyValuePair, is not accepted because it is a value type (see #3604) and cannot be normally navigated because it is keyless, which is normal for an association record. It can be navigated as an owned entity but this is kinda hard to figure out because that is advanced stuff (at least in the exposition order). This problem is so severe it should at least be mentioned in the handout. |
@yecril71pl Can you share an example of C# code you want to use to define the entity types in this case? |
class Person {
public int Id { get; set; }
public IEnumerable < PersonAddress > Addresses { get; set; }
…
}
class Address {
public int Id { get; set; }
…
}
class PersonAddress {
public Person Person { get; set; }
public Address Address { get; set; }
} |
@yecril71pl Supporting this shape is exactly what is covered by dotnet/efcore#3864 |
I understand, I just do not approve of your workaround. I believe I have a better one. |
@yecril71pl Feel free to comment on that issue with your better workaround. People can choose to use it if they wish. |
Is #3606 (comment) |
I have a situation when entity A has many entities C and entity B has many entities C too, entities A and B being different and unrelated. If I understand the description correctly, the framework will inject optional shadow foreign key for entities A and B into the property C. I would prefer to have separate join entities AhasC and BhasC in the model.
I understand that I can say "C has many A with many via A.Cs" but that reads counter-intuitive (a location has many inhabitants reads all right, but inhabitants is an abstract word coined specially for this case, so as to avoid the cringe of saying a location has many persons; the construct is by no means generic). I would expect to be able to say "A has many C with many" but that does not work because the sentence is incomplete without a collection property. But C does not have a collection property for A, nor should it have.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: