我一直在阅读所有关于在其中建立一对一关系的人的 Google 和 SO 页面,EF但它对我不起作用。
这是我的模型:
帐户:
public int Id {get; set;}
public virtual AccountConfig AccountConfig {get; set;}
账户地图:
HasKey(t => t.Id);
HasRequired(t => t.AccountConfig)
.WithOptional();
账户配置:
public int Id {get; set;}
public int AccountId {get; set;}
public virtual Account Account {get; set;}
账户配置图:
HasKey(t => t.Id);
HasRequired(t => t.Account)
.WithOptional(t => t.AccountConfig);
执行时,AccountConfig属性 on和属性 onAccount是不正确的记录(巧合的是,检索到的与 相同,但我不知道这是否意味着什么)。NULLAccountAccountConfigAccount.IdAccountConfig.Id
在数据库中,Account表没有对AccountConfig记录的引用,但AccountConfig表有对Account使用AccountId列的记录的引用。
最终结果是我可以引用AccountConfigfromAccount和(如果可能的话)引用Accountfrom AccountConfig。