3

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!!

mitomed
  • 2,006
  • 2
  • 29
  • 58

1 Answers1

5

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.

Community
  • 1
  • 1
David Anderson
  • 13,558
  • 5
  • 50
  • 76
  • So I assume it has nothing to do with the fact I could see the link after checking it. It just happens to refresh then and not before. Thanks – mitomed Apr 13 '12 at 09:53
  • If that property was required for your association, then yes, not having the property set as an entity key could cause your association not to appear. Associations in entity work very similar to associations in SQL. – David Anderson Apr 13 '12 at 10:25