C# 无法检索模型的元数据
我正在尝试在Visual Studio 2013升级5的控制器上添加脚手架项。但它给出了一个错误,如: “运行所选生成器时出错:'无法检索' XYZ.Models.Student.的元数据。出现了一个或多个验证错误 在模型生成期间检测到:XYZ.DAL.Student::EntityType “Student”未定义键。请定义此实体类型的键。 学生:实体类型:“学生”基于具有 没有定义任何键 模范班C# 无法检索模型的元数据,c#,entity-framework,C#,Entity Framework,我正在尝试在Visual Studio 2013升级5的控制器上添加脚手架项。但它给出了一个错误,如: “运行所选生成器时出错:'无法检索' XYZ.Models.Student.的元数据。出现了一个或多个验证错误 在模型生成期间检测到:XYZ.DAL.Student::EntityType “Student”未定义键。请定义此实体类型的键。 学生:实体类型:“学生”基于具有 没有定义任何键 模范班 public class Student { public int SID { get;
public class Student
{
public int SID { get; set; }
public string Name { get; set; }
public string SurName { get; set; }
public string PhoneNumber { get; set; }
public virtual ICollection<Record> Records { get; set; }
}
公共班级学生
{
公共int SID{get;set;}
公共字符串名称{get;set;}
公共字符串姓氏{get;set;}
公共字符串PhoneNumber{get;set;}
公共虚拟ICollection记录{get;set;}
}
我假设SID是您的主键,如果是,请添加以下属性:
[Key]
public int SID { get; set; }
注意:它位于下面:使用System.ComponentModel.DataAnnotations;
请参阅中的关键部分