实体:在视图和表之间添加导航属性 [英] Entities: Adding a Navigation Property between a View and Table

查看:113
本文介绍了实体:在视图和表之间添加导航属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如下图所示,ProjectTask和Dependency表之间存在一对多关系.

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?

谢谢, 安倍(Abe)

Thanks, Abe

以下是映射图的链接:

映射图

推荐答案

默认情况下,当您向模型中添加数据库视图时,Entity Framework会假设每一列都是主键的一部分.如果您添加未定义主键的表,它也会做同样的事情.

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.

解决方案是使用XML编辑器手动编辑edmx文件并自己定义主键.找到< EntityType>您的视图的标记(< EntityType Name ="MyView">),那么将有一个< Key>元素.从该元素中删除所有非关键列.

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.

这篇关于实体:在视图和表之间添加导航属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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