我收到了这个错误:
无法确定之间关联的主要结束 类型CustomerDetail和Customer。
以下是我的Customer
和CustomerDetail
型号
[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
与CustomerDetail
的关系为1:1。
答案 0 :(得分:10)
我认为您必须在ForeignKey
属性上指定Customer
关系,该属性映射到实体上存在的关键属性。
[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指的是一个不同的错误,但其目标与您要实现的目标类似。