簡體   English   中英

創建強類型視圖時出現錯誤,無法確定復合主鍵

[英]Getting error unable to determine composite primary key while creating strongly typed view

我正在使用ASP.NET-MVC應用程序,正在嘗試從控制器創建強類型視圖,但是卻出現了如下圖所示的錯誤

在此處輸入圖片說明

在此處輸入圖片說明

模型類

public class PropertyRentingApplication
{
     public PropertyRentingApplication() { }


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

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

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

     [Display(Name = "Application Reference")]
     [MaxLength(150)]
     [Required(ErrorMessage = "Application Reference")]
     public string ApplicationReference { get; set; }

     [Display(Name = "Date Of Application")]
     [Required(ErrorMessage = "Require Date of Application Been Submitted")]
     public System.DateTime DateOfApplication { get; set; }

     [Display(Name = "Secure Entire Property")]
     [Required(ErrorMessage = "Require Information on If You Want to Secure Entire Property")]
     public bool SecureEntireProperty { get; set; }

     [Display(Name = "Application Status")]
     [MaxLength(50)]
     [Required(ErrorMessage = "Require Application Status")]
     public string ApplicationStatus { get; set; }

     public PropertyType PropertyType { get; set; }
     public Student Student { get; set; }

}

我已更新如下“ [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)]等修飾鍵列,以定義這些列在鍵中出現的順序

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM