Skip to content
Advertisement

In entity framework core, how we can set relationship for a table, when two fields is mapping to primary key of the another table

In entity framework core, how we can set relationship for a table, when two fields is mapping to primary key of the another table. For example I have two table namely Users & CashBox.

Users Table

Field Value
UserId int
UserName string

CashBox Table

Field Value
CashBoxId int
ActivatedBy int
DeactivatedBy int

In this case, activatedby & deactivatedby has to be linked with user table. Need to know who activated cashbox & who deactivated cashbox.

Using EF core code first approach.

Advertisement

Answer

With the following entity models –

you can configure the relationship as –

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement