实体框架的[Key]属性对我不起作用。我有一个console
应用程序,我想添加这个类:无法找到类型或名称空间名称'Key'
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; }
}
我得到这些错误:
类型或命名空间名称“键”找不到(是否使用缺少指令或程序集引用?)
类型或命名空间名称“KeyAttribute”找不到(是否缺少using指令或程序集引用?)
我已经加入这个使用:
using System.Data.Entity;
而且我加入到项目中的这些引用:
EntityFramework EntityFramework.SqlServer System.ComponentModel.DataAnnotations
我使用EF6和VS2012。
我缺少什么参考?
将光标置于'Key'键上,按Ctrl +句点。如果出现菜单,请选择添加'using'语句的选项。 – gunr2171 2014-09-25 18:08:00
Ahh宾果。非常感谢你。我需要“使用System.ComponentModel.DataAnnotations;” – Guerrilla 2014-09-25 18:14:29