jer*_*mny 5 .net c# entity entity-framework
我一直在阅读有关建立一对一关系的人的所有谷歌和SO页面,EF但它只是不适合我.
这是我的模型:
帐户:
public int Id {get; set;}
public virtual AccountConfig AccountConfig {get; set;}
Run Code Online (Sandbox Code Playgroud)
帐户地图:
HasKey(t => t.Id);
HasRequired(t => t.AccountConfig)
.WithOptional();
Run Code Online (Sandbox Code Playgroud)
帐户配置:
public int Id {get; set;}
public int AccountId {get; set;}
public virtual Account Account {get; set;}
Run Code Online (Sandbox Code Playgroud)
帐户配置图:
HasKey(t => t.Id);
HasRequired(t => t.Account)
.WithOptional(t => t.AccountConfig);
Run Code Online (Sandbox Code Playgroud)
在执行时,AccountConfig性能上Account是NULL和Account财产AccountConfig是不正确的记录(巧合的是,检索到的Account.Id是一样的AccountConfig.Id,但我不知道这意味着什么).
在数据库中,该Account表没有对AccountConfig记录的引用,但该AccountConfig表具有对Account使用该AccountId列的记录的引用.
最终的结果是我可以引用AccountConfigfrom Account和(如果可能的话)引用Accountfrom AccountConfig.
| 归档时间: |
|
| 查看次数: |
6131 次 |
| 最近记录: |