There is no Key attribute in EF CTP 5

According to a blog post here, Data Annotations in the Entity Framework should have an attribute for a column called "Key" that allows you to mark the primary key of an object. However, I cannot find this in .Net 3.5 or .Net 4.0.

What did I miss? I have included a link to EntityFramework.dll, and I checked all the attributes in System.ComponentModel.DataAnnotations , but I can not find it. alt text

I installed my project in .Net 4.0 full (no client profile).

Any ideas?

+4
source share
2 answers

KeyAttribute is only .NET 4, and it is in the System.ComponentModel.DataAnnotations assembly, so make sure you specify it.

+15
source

Perhaps your project is not targeting Framework 4.0, so when you add the System.ComponentModel.DataAnnotations link, it will not match version 4.0, that is, the version that has the definition of "Key".

Try deleting the current DataAnnotation link, then change the project target structure (right-click the project β†’ Properties β†’ Application β†’ Target structure) to .Net 4.0, and then add the DataAnnotations link again. Worked for me;)

+6
source

Source: https://habr.com/ru/post/1333929/


All Articles