EF4 CTP5代码优先:可选的一对一映射,访问模型上的外键字段。 [英] EF4 CTP5 Code First: Optional one to one mapping, accessing foreign key fields on the model.

查看:64
本文介绍了EF4 CTP5代码优先:可选的一对一映射,访问模型上的外键字段。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一对多映射中,甚至是自引用一个映射到0..1我已经能够同时使用导航属性和外键字段:

In a one to many mapping, or even a self-referencing one to 0..1 I've been able to use both the navigational property and the foreign key fields with no problem:


public virtual Group Group { get; set; }
public int? GroupId { get; set; }

推荐答案

Chris Chris,

Hi Chris,

在这个阶段,EF通常只支持在一个实体中暴露FK属性:多个关系(除非FK也是PK)。这有点人为,但EF的副作用不支持非PK独特约束。目前我们正在为EF的独特约束支持
,但它不会出现在我们的第一个Code First RTM中。

At this stage EF in general only supports exposing FK properties on your entities in one:many relationships (unless the FK is also the PK). This is somewhat artificial but a side effect of EF not supporting non-PK unique constraints. We are working on support for unique constraints for EF at the moment but it won't be there in our first RTM of Code First.

抱歉没有更好的答案因为在这个阶段确实没有解决方法。

Sorry not to have a better answer as there really isn't a workaround at this stage.

~Rowan


这篇关于EF4 CTP5代码优先:可选的一对一映射,访问模型上的外键字段。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆