I am trying to figure out how to make this work in EF. I have two entities Employee and User. I need to make it so the User has an optional mapping to the Employee. If there is a mapping, then it would be 1:1.
Basically this system can be accessed by employees and also by outside vendors, but I want one table to manage logons: Users.
How do I define this realtionship in EF with fluid configurations?
You just need to set simple fluent configuration:
or in reverse order:
EF will use Employess’s PK as FK to user – that is mandatory requirement for EF to correctly use one-to-one relation. In case of Data annotation it is enough to mark Employee’s PK with
ForeignKeyattribute pairing it withUsernavigation property: