Frage

Everything I find through Google refers to Code First so I'm wondering what the Key attribute is actually doing in regards to a Database First design? I'm mainly curious because a lot of the entities contain composite keys so I've been adding the Key annotation to the respective properties, but is this really necessary? And if so, what do I gain from it?

War es hilfreich?

Lösung

If you're using the database-first workflow (i.e. you have an .edmx file in your solution). Then the Key attribute will have no effect.

However, if you're using the code-first workflow to map to an existing database, the Key attribute tells code first that that property is part of the entity's primary key.

For more info on the different workflows see this video: Visual Studio Toolbox: Entity Framework Part 1

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top