「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; }
}
我遇到了这些错误:
我已添加了以下 using:找不到类型或命名空间名称“Key”(您是否缺少 using 指令或程序集引用?)
找不到类型或命名空间名称“KeyAttribute”(您是否缺少 using 指令或程序集引用?)
using System.Data.Entity;
我已将以下引用添加到项目中:
EntityFramework EntityFramework.SqlServer System.ComponentModel.DataAnnotations
我正在使用EF6和VS2012。
我缺少哪个引用?
Key
上,按下 Ctrl + 句点。如果出现菜单,请选择添加using
语句的选项。 - gunr2171