I have two tables:
RequirementId - PK
FixtureId - PK
RequirementId - FK / NULLABLE / Unique Constraint
A Fixture can only have 1 Requirement, no other Fixture should be able to reference the same Requirement. It is not mandatory for a Fixture to have a Requirement, its optional.
What i have done is, in Sql Server i have placed a Unique constraint on the RequirementId column in the Fixture table. How do I setup the mapping for this in Entity Framework CTP 5 ?
Also would it be possible to have a bidirectional navigation property on each entity?
public class Fixture
{
public int FixtureId { get; set; }
public Requirement Requirement { get; set; }
}
public class Requirement
{
public int RequirementId { get; set; }
public Fixture Fixture { get; set; }
}
Maybe im getting this all wrong, so any advice would be great. Thanks in advance
What you are after is called One-to-One Foreign Key Associations and like Ladislav mentioned is not natively supported by EF. However, I showed how to implement it with Code First in this article.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With