문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top