Type or namespace name "Key" not found

The [Key] attribute for the entity structure doesn't work for me. I have an application console

and I am trying to add this class:

public class Post
    public int IDPost { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }
    public int IDBlog { get; set; }
    public virtual Blog Blog { get; set; }


I am getting the following errors:

Can't find the name or namespace name "Key" (are you missing a using directive or an assembly reference?)

Could not find type or namespace name 'KeyAttribute' (are you missing a using directive or assembly reference?)

I added this using:

using System.Data.Entity;


And I have these links added to the project:


I am using EF6 and VS2012.

Which link am I missing?


source to share

2 answers

In EF6, System.Data.Entity has been replaced by System.Data.Entity.Core. Make sure you don't reference any EF5 dlls anymore and replace them with include with



Also [Key]

comes from



namespaces. If you include it in the using statements for your class, it should compile.



I got the same error using Visual Studio 2010 when I was building my asp.net Webforms application. I followed these steps and it worked for me.

  • open nugetpackage manager and search for System.data.entity.
  • install it.
  • link to use System.ComponentModel.DataAnnotations;


All Articles