how to use Foreign key in L2E or EF?
- by 5YrsLaterDBA
I have a User table which has a PrivilegeId foreign key points to a Privilege table and is the primary key there.
In Entity Framework, the VS will not generate a PrivilegeId variable under Users for you. It will generate a Privilege property and PrivilegeReference property for you instead.
When I load a User, the Privilege property is null by default. That means EF does not load refered entity for you automatically. I think I may did something wrong? I cannot load Privilege separatedly because I have no info about the Privilege at that time. I guess EF should load the refered entities for me but I missed something.
anybody can help me?