I'm getting this error:
Unable to determine the principal end of an association between the types CustomerDetail and Customer.
Here is my Customer
and CustomerDetail
models
[Table("CUSTOMER")]
public class Customer
{
[Required]
[Column("CUSTOMER_ID")]
public int Id {get; set;}
[Column("FIRST_NAME")]
public string FirstName {get; set;}
// other fields
public virtual CustomerDetail customerDetail {get; set;}
}
[Table("CUSTOMER_DETAIL")]
public class CustomerDetail
{
[Required]
[Column("CUSTOMER_DETAIL_ID")]
public int Id {get; set;}
// other fields
public virtual Customer Customer {get; set;}
}
Customer
to CustomerDetail
has a 1:1 relation.
I think that you have to specify a ForeignKey
relation on the Customer
property that maps to the key property exists on the entity.
[Table("CUSTOMER_DETAIL")]
public class CustomerDetail
{
[Required]
[Column("CUSTOMER_DETAIL_ID")]
public int Id {get; set;}
// other fields
[ForeignKey("Id")]
public virtual Customer Customer {get; set;}
}
This question refers to a different error, but has a similar goal to what you are trying to achieve.