【发布时间】:2017-01-11 21:36:51
【问题描述】:
关于这个错误有很多线程,我已经阅读了大约半打。 (其中一些不适用,因为关系不是 1:1。)我尝试了一些方法,但仍然出现错误。
我有两张桌子,Account 和 AccountSettings。他们有 1:1 的关系。但是,Account 是主要的。它可以在没有AccountSettings 的情况下存在,但反过来不行。
这就是我原来的样子……
public class Account
{
[Key]
public int AccountID { get; set; }
public int? AccountSettingID { get; set; }
[ForeignKey("AccountSettingID ")]
public virtual AccountSetting AccountSetting { get; set; }
}
然后……
public class AccountSetting
{
[Key]
public int AccountSettingID { get; set; }
public int AccountID { get; set; }
[ForeignKey("AccountID ")]
public virtual Account Account { get; set; }
}
但这让我犯了错误:
无法确定类型“EZHomes.Data.Model.AccountSetting”和“EZHomes.Data.Model.Account”之间关联的主体端。此关联的主体端必须使用关系流式 API 或数据注释显式配置。
如何指定Account为原则?
谢谢!
【问题讨论】:
标签: c# asp.net-mvc ef-code-first code-first