无法确定类型之间关联的主体结束 [英] Unable to determine the principal end of an association between the types
本文介绍了无法确定类型之间关联的主体结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到此错误:
无法确定
类型之间的关联的主体结尾CustomerDetail和客户
Unable to determine the principal end of an association between the types CustomerDetail and 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;}
}
客户
到 CustomerDetail
具有1:1关系。
Customer
to CustomerDetail
has a 1:1 relation.
推荐答案
我认为你必须指定一个 ForeignKey
c>客户属性映射到实体上存在的关键属性。
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.
这篇关于无法确定类型之间关联的主体结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文