Properties referred by the Principal Role App must be exactly identical to the key of the EntityType

asp.net asp.net-mvc-3 c# entity-framework

Question

I'm using EF DB first.

I have made a view.

Mapped it to EF.

Now I get the following error:

Error 2 Error 111: Properties referred by the Principal Role App must be exactly identical to the key of the EntityType MaMDBModel.App referred to by the Principal Role in the relationship constraint for Relationship MaMDBModel.FK_AppsData_App. Make sure all the key properties are specified in the Principal Role. D:\MaM\Dev\MamAdmin_1.0\MaMDBEntityFramework\MaMModel.edmx 768 11 MaMDBEntityFramework

this is my edmx:

http://ge.tt/3rRWTOR/v/0?c

1
11
11/11/2012 1:28:41 PM

Accepted Answer

There is an error message as comment in your edmx file:

<!--Errors Found During Generation:
warning 6002: The table/view 'MamDB.dbo.VW_APPSDATA' does not have a primary key
defined. The key has been inferred and the definition was created as a read-only
table/view.
-->

The key that EF has inferred is probably wrong. According to the message you should define a primary key for your view in the database.

9
11/11/2012 2:32:17 PM

Popular Answer

Just had the same error in a huge project where basically the Diagram view of the .edmx file is so big you don't even find the concerning table without searching for days.

Here is how I could solve it:

  • Open the .edmx file
  • Open the Model Browser (CTRL+1 / VIEW > Other Windows > Entity Data Model Browser)
  • Find the table from the error message (i.e. VW_APPSDATA) in Entity Types
    • (Maybe right click, show in Diagram)
  • Compare the Entity Type column definitions with your database definition

In my case, I had added a column, which EF thought to be a PK, but it was not. So I hat to set the column property Entity Key = False, and that solved it for me.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow