EF4从3.5升级如何向模型添加外键字段
我已将我的项目从 FW 3.5 升级到 4.0。我试图获取模型的外键列,显然,VS 不会在“从数据库更新”命令上执行此操作。因此,向实体添加了一个整数列并将其映射到外键字段。当我编译时,我收到经典的 EF 错误“错误 3007:从行开始的映射片段出现问题列在两个片段中都映射到不同的概念侧属性” 我想知道是否需要做一些特殊的事情(即使我必须手动编辑 edmx 文件中的 xml)以便可以访问外键值,而不是以旧方式加载导航对象。我的印象是 EF4 本机公开了外键属性和导航属性。可能是我错了,或者 MS 只是在虚张声势:)。顺便说一句,我看到了新添加的实体的这些属性。从头开始重新创建模型并不是一种选择,因为应用程序已经投入生产。
任何帮助表示赞赏。谢谢
I have upgraded my project from FW 3.5 to 4.0. I was trying to get the Foreign key columns to the model, and obviously, VS does not do that on the "update from Database" command. so went in added an integer column to the entity and mapped it to the Foreign key field. When I compile I get the classic EF error "error 3007: Problem in mapping fragments starting at lines Column(s) are being mapped in both fragments to different conceptual side properties"
I was wondering If I need to do something special (even If I have to manually edit the xml in the edmx file) so that can access the Foreign key values, instead of loading the navigation object int he old way. I was under the impression the EF4 natively exposes the Foreign key properties along with Navigation properties. May be I am wrong or MS is just bluffing :). BTW I see those properties to the newly added entities. Recreating the model the model from the ground up is not an option as the application is already in production.
Any help is appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是你想将独立关联升级为外键关联(我已经描述了它们之间的区别此处)。添加新属性只是此升级过程的一个步骤。您还必须更改实体之间的关系以使用引用约束而不是关联映射。 这里< /a> 你有关于这个主题的非常好的博客文章。
The problem is that you want to upgrade the independent association to the foreign key association (I have described the difference between them here). Adding a new property is just one step of this upgrade process. You must also change the relation between entities to use referential constraints instead of an association mapping. Here you have very nice blog post about the topic.