I am trying to create a zero to one relationship with code first entity framework. With the sample code below, I am getting error message:
Unable to determine the principal end of an association between the types 'CompanyView' and 'MemberView'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
With this error, I have tried added in a configuration to fix this.
modelBuilder.Entity<CompanyView>().HasOptional(x => x.MemberView).WithOptionalPrincipal(x => x.CompanyView);
Which ended up with another error message.
CompanyView_MemberView_Target: : Multiplicity is not valid in Role 'CompanyView_MemberView_Target' in relationship 'CompanyView_MemberView'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.
Anyone have any idea on what is going one here? Thanks.
public class CompanyView
{
[Key]
public Guid Id { get; private set; }
public Guid? MemberId { get; private set; }
[ForeignKey("MemberId")]
public MemberView MemberView { get; private set; }
}
public class MemberView
{
[Key]
public Guid Id { get; private set; }
public Guid? CompanyId { get; private set; }
[ForeignKey("CompanyId")]
public CompanyView CompanyView { get; private set; }
}
The end result I would expected is as below: A MemberView can have 0 or 1 CompanyView, each CompanyView can have 0 to 1 MemberView.