实体:在视图和表之间添加导航属性

发布于 2024-08-07 01:36:31 字数 339 浏览 0 评论 0原文

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

数据库图

实体尝试将视图中的每个字段映射到依赖关系表中的字段,这是行不通的。

关于如何添加导航属性有什么建议吗?

谢谢, Abe


以下是映射图的链接:

映射图

As you can seen in the diagram below there is a one-to-many relationship between the ProjectTask and Dependency table.

Database Diagram

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:

Mapping Diagram

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葵雨 2024-08-14 01:36:31

默认情况下,当您向模型添加数据库视图时,实体框架将假定每个列都是主键的一部分。如果您添加未定义主键的表,它也会执行相同的操作。

解决方案是使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文