实体:在视图和表之间添加导航属性
如下图所示,ProjectTask 和 Dependency 表之间存在一对多关系。
实体尝试将视图中的每个字段映射到依赖关系表中的字段,这是行不通的。
关于如何添加导航属性有什么建议吗?
谢谢, Abe
以下是映射图的链接:
As you can seen in the diagram below there is a one-to-many relationship between the ProjectTask and Dependency table.
Entities tries to map every field in the View to fields in the Dependency table, which wouldn't work.
Any suggestions on how I can add the navigation property?
Thanks,
Abe
Here's the link to the Mapping diagram:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,当您向模型添加数据库视图时,实体框架将假定每个列都是主键的一部分。如果您添加未定义主键的表,它也会执行相同的操作。
解决方案是使用 XML 编辑器手动编辑 edmx 文件并自行定义主键。找到为您的视图标记 (),然后会有一个元素。从该元素中删除所有非键列。
By default, when you add a database view to your model, Entity Framework will assume every single column is part of the primary key. It does the same thing if you add a table without a primary key defined.
The solution is to manually edit the edmx file with an XML editor and define the primary key yourself. Find the <EntityType> tag for your view (<EntityType Name="MyView">), then there will be a <Key> element. Remove any non-key columns from that element.