I have 3 classes A, B and AB. Both class A and class B are independent on each other. But AB depends on A and B. I would like to achieve a " Zero or One to Zero or One" relationship between A and B using Entity Framework code-first.
Can someone tell me why this doesn't work? Or am I completely wrong? Thank you!
public class A
{
public int Id { get; set; }
public string PropertyName { get; set; }
public virtual AB AB { get; set; }
}
public class B
{
public int Id { get; set; }
public string PropertyName { get; set; }
public virtual AB AB { get; set; }
}
public class AB
{
[Key, ForeignKey("A"), Column(Order = 0)]
public int AId { get; set; }
[Key, ForeignKey("B"), Column(Order = 1)]
public int BId { get; set; }
public virtual A A { get; set; }
public virtual B B { get; set; }
}
I'm getting this error:
AB_B_Source: : Multiplicity is not valid in Role 'AB_B_Source' in relationship 'AB_B'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.
AB_A_Source: : Multiplicity is not valid in Role 'AB_A_Source' in relationship 'AB_A'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.