You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This looks like a many-to-many relationship. (That is, a user can have many cars, and a car can have many users.) If so, check out many-to-many mapping in the docs.
I don't think this is a many to many relationship, because while there can be multiple cars associated with one user, only one of those cars can be set to CarId on the user entity. So it can be 1:N for user:car and 1:N for car:user but in both cases there are dangling entities in the N. And this is what I am looking to prevent - to have EF ensure for me that this always stays 1:1. Is that possible?
I am trying to figure out if EF Core can be set so that it keeps ID properties on both ends of a foreign key in sync. I have a model like this:
I use the fluent API to tell EF Core which entity is the principal one and which is the dependent one:
When I do this and then insert:
The database ends up in this state (in parentheses are the respective ID property values):
I would like to achieve the dependent ID property to contain the ID of the principal entity after save, so:
I tried to set two FKs, one in each direction, but that didn't help.
Is this possible to achieve using EF Core?
EF Core version: 2.2.2
Database Provider: SQL Server
Operating system: Windows
IDE: CLI
The text was updated successfully, but these errors were encountered: