I'm having trouble mapping a one to one relationship in EF 6. My classes are:
public class Membership
{
[Key]
public decimal Id { get; set; }
[ForeignKey("Id")]
public virtual User User { get; set; }
}
public class User
{
[Key]
public decimal Id { get; set; }
[ForeignKey("Id")]
public virtual Membership Membership { get; set; }
}
I am getting the exception:
Unable to determine the principal end of an association between the types 'User' and 'Membership'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
I think my issue is both tables has the same key value and do not store the key of the other. Thanks.