Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法检索模型的元数据_C#_Entity Framework - Fatal编程技术网

C# 无法检索模型的元数据

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;

我正在尝试在Visual Studio 2013升级5的控制器上添加脚手架项。但它给出了一个错误,如:

“运行所选生成器时出错:'无法检索' XYZ.Models.Student.的元数据。出现了一个或多个验证错误 在模型生成期间检测到:XYZ.DAL.Student::EntityType “Student”未定义键。请定义此实体类型的键。 学生:实体类型:“学生”基于具有 没有定义任何键

模范班

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;

请参阅中的关键部分