C# 创建强类型视图时,获取错误无法确定复合主键

C# 创建强类型视图时,获取错误无法确定复合主键,c#,asp.net-mvc-5,entity-framework-6,data-annotations,C#,Asp.net Mvc 5,Entity Framework 6,Data Annotations,我正在开发ASP.NET-MVC应用程序,我正在尝试从控制器创建强类型视图,但我遇到如下错误,如图所示 模范班 我已经更新如下“[Column(Order=1)]”,但仍然遇到相同的错误 [Key] [Display(Name = "Application ID")] [Column(Order = 0)] public int ApplicationID { get; set; } [Key, ForeignKey("PropertyType")]

我正在开发ASP.NET-MVC应用程序,我正在尝试从控制器创建强类型视图,但我遇到如下错误,如图所示

模范班 我已经更新如下“[Column(Order=1)]”,但仍然遇到相同的错误

[Key]
     [Display(Name = "Application ID")]
     [Column(Order = 0)]
     public int ApplicationID { get; set; }

     [Key, ForeignKey("PropertyType")]
     [Display(Name = "Property Type ID")]
     [Column(Order = 2)]
     [Required(ErrorMessage = "Require Property Type ID")]
     public int PropertyTypeID { get; set; }

     [Key, ForeignKey("Student")]
     [Display(Name = "Student ID")]
     [Column(Order = 1)]
     [Required(ErrorMessage = "Require Student ID")]
     public int StudentID { get; set; }

您需要使用
[Column(Order=0)]
[Column(Order=1)]
等装饰键列,以定义这些列在键中的显示顺序

您需要使用
[Column(Order=0)]
等装饰键列,要定义这些列在键中的显示顺序,不管是否重要,但在您的代码中,StudentID被标记为键,但不在您的列的屏幕截图中。@marc_s:请将其作为答案发布,因为它是答案。否则,OP将无法接受,此问题将永远保持“未回答”。请查看底部的问题,我添加了[Column(Order=0)],但仍然会出错!!!!!
[Key]
     [Display(Name = "Application ID")]
     [Column(Order = 0)]
     public int ApplicationID { get; set; }

     [Key, ForeignKey("PropertyType")]
     [Display(Name = "Property Type ID")]
     [Column(Order = 2)]
     [Required(ErrorMessage = "Require Property Type ID")]
     public int PropertyTypeID { get; set; }

     [Key, ForeignKey("Student")]
     [Display(Name = "Student ID")]
     [Column(Order = 1)]
     [Required(ErrorMessage = "Require Student ID")]
     public int StudentID { get; set; }