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
{
[Key]
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:
EntityFramework EntityFramework.SqlServer System.ComponentModel.DataAnnotations
I am using EF6 and VS2012.
Which link am I missing?
source to share
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
System.Data.Entity.Core
Also [Key]
comes from
System.ComponentModel.DataAnnotations
namespaces. If you include it in the using statements for your class, it should compile.
source to share