The title of this post suggests this may be a simple scenario like this answer but it's actually a bit more complicated.
I'm working on a Blazor site that will serve as a new frontend to an existing set of tables. There is a table of company Clients
with a primary key called ClientId
.
There are also Users
, which represent company employees, with a primary key of UserId
.
All of the columns in Client
are stored in this table with the exception of the client's relationship to the user (good relationship, don't know them well, etc.). In the existing EmployeeRelationship
table, the ClientId
and UserId
both serve as the primary key, as the EmployeeRelationship
is dependent on both the Client
and User
. This is fine but I have been unable to make EF Core accept this relationship.
What I'd like to do is add the EmployeeRelationship
property to my Client
object such that I can reference it like Client.EmployeeRelationship.Description
. The problem then is the User
object, as EF has no idea what to do with the secondary PK on EmployeeRelationships
if I call .Include
, as there is no FK for User
in the Client
object.
Would it be possible to provide this foreign key when I call Include
on Client
?
For example, something like:
Context.Clients.Select(x => x).Include(x => EmployeeRelationship, UserId);
Where {UserId} can be used to provide the missing foreign key.
If not, how can I get around this issue? I also find it odd that whoever created this table used the UserId and ClientId as the primary key because it means the User/Client tables share the same name for the PK, but I'm not sure if this is a problem. It seems like the UserId and ClientId should be foreign keys but this still wouldn't solve my problem.