Entities: Adding a Navigation Property between a V

2019-02-27 18:58发布

问题:

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:

Mapping Diagram

回答1:

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.