-1

I've created an Entity Data Model from my SQL Server database. Despite only having one primary key in each of my tables, almost all of my properties are marked as Entity Keys. I can of course modify these, but can anyone tell me why this happens?

Jonathan
  • 13,947
  • 17
  • 94
  • 123

2 Answers2

0

Most likely by default it has determined that the columns marked as keys make the entry unique. It will do this with imported views as well.

That said, I have imported table definitions with unique constraints and primary keys and have not seen this behavior.

Rockdocta
  • 604
  • 1
  • 9
  • 26
0

Open the edmx file with the Xml editor (right click the Edmx file in the solution and select "Open with...). Once you do it you will see Xml comments in the file explaining why the existing key column could not be used. Oftentimes it is because the column is of a type that is not supported by EF (e.g. HierarchyId) so the column is not supported and therefore is excluded. This way you end up with a table without a key column and an artificial key will be created which, in such cases, consists of all columns of types that are valid types for key columns (e.g. columns of spatial types will be excluded from this list since they are not valid key columns is EF)

Pawel
  • 31,342
  • 4
  • 73
  • 104