Mapping one to one foreign key relationships in Entity Framework 4.0?
Posted
by John K.
on Stack Overflow
See other posts from Stack Overflow
or by John K.
Published on 2010-06-02T16:31:41Z
Indexed on
2010/06/02
16:34 UTC
Read the original article
Hit count: 291
entity-framework
Hello all,
I'm sure I'm missing something very simple, but let's say I have two entities, Employee and EmployeeType.
Employee type would contain values like 'Full time', 'Contractor', 'Intern', etc.
An Employee entity would contain one, and only one EmployeeType value.
So I am designing a new .edmx model using the Model-First approach and generating my actual sql server data schema from the model.
I want to add an integer type foreign key id into my Employee entity, EmployeeTypeId, which will map to the primary key of the EmployeeType entity.
So I've gone ahead and done that in my Employee entity. Where I'm stuck is how, though the Entity Framework designer, to enforce the 1:1 referential constraint on that EmployeeTypeId property? Or does the EF handle that automatically behind the scenes?
thanks in advance, John
© Stack Overflow or respective owner