【发布时间】:2015-08-07 11:37:10
【问题描述】:
我在 ASP.NET-MVC 应用程序中有 ViewModel 类,当我尝试创建视图时 --> 来详细说明记录。我收到实体没有主键的错误。我有测试个人模型类,它们工作正常,我不是我在这里缺少的......
ViewModel 类
public class RentingApplicationsViewModel
{
public RentingApplicationsViewModel() {
_PropertyRentingApplicationModel = new PropertyRentingApplication();
_PropertyTypeModel = new PropertyType();
}
public PropertyRentingApplication _PropertyRentingApplicationModel { get; set; }
public PropertyType _PropertyTypeModel { get; set; }
}
模型类
[Table("PropertyRentingApplication")]
public class PropertyRentingApplication
{
public PropertyRentingApplication() { }
[Key]
// [Column(Order = 0)]
[Display(Name = "Application ID")]
public int ApplicationID { get; set; }
//[Key]
//[Column(Order = 1)]
[Display(Name = "Property Type ID")]
[Required(ErrorMessage = "Require Property Type ID")]
public int PropertyTypeID { get; set; }
//[Key]
//[Column(Order = 2)]
[Display(Name = "Student ID")]
[Required(ErrorMessage = "Require Student ID")]
public int StudentID { get; set; }
[Display(Name = "Application Reference")]
[MaxLength(150)]
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; }
public ICollection<AdditionalTenant> AdditionalTenants { get; set; }
}
....
[Table("PropertyType")]
public class PropertyType
{
public PropertyType() { }
[Key]
[Display(Name = "Property Type ID")]
public int PropertyTypeID { get; set; }
[Display(Name = "Property Type")]
[MaxLength(250)]
[Required(ErrorMessage = "Require Property Type i.e. Flat, House, Studio")]
public string Type { get; set; }
[Display(Name = "Title")]
[MaxLength(250)]
[Required(ErrorMessage = "Require Property Type Title")]
public string Title { get; set; }
public ICollection<Property> Properties { get; set; }
public ICollection<PropertyRentingPrice> PropertyRentingPrices { get; set; }
}
【问题讨论】:
标签: asp.net-mvc-5 entity-framework-6 asp.net-mvc-viewmodel