Question

in a C# project, using EF Database first I've added a foreign key to a table using SQL server management studio.

After that, back to Visual Studio I've updated the model from the database but I couldn't see the "link" (i.e. the line joining the two tables in the .edmx diagram) between the two affected tables. So in the dropdown over the child table I saw this option "Entity key" and when I clicked it the "link" appeared. To be honest, I don't know and I can't understand what it does, cause I can check or uncheck it now without losing the, again let's say "link".

Do you know why this behaviour?

Thanks!!

Was it helpful?

Solution

EntityKey is the Entity idea of a Primary Key in a (SQL in your case) database. You should set it for any column that is a primary key, and then you can setup your Entity Associations to match your database associations.

Working with Entity Keys.

Setting correct EntityKeys is a must for getting correct results from SQL Server, because EntityKeys are used as an internal caching key.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top