mvc viewmodel entity has no key Error when trying to create view from controller entity-framework-6


I have ViewModel class in ASP.NET-MVC application and when I am trying to create view --> to detail the records. I am getting error that entity don't have primary key. I have test invidual model classes and they are working fine, I am not what I am missing here...

ViewModel class

public class RentingApplicationsViewModel
    public RentingApplicationsViewModel() {

        _PropertyRentingApplicationModel = new PropertyRentingApplication();
        _PropertyTypeModel = new PropertyType();

    public PropertyRentingApplication _PropertyRentingApplicationModel { get; set; }
    public PropertyType _PropertyTypeModel { get; set; }


Model class

public class PropertyRentingApplication
     public PropertyRentingApplication() { }

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

     //[Column(Order = 1)]
     [Display(Name = "Property Type ID")]
     [Required(ErrorMessage = "Require Property Type ID")]
     public int PropertyTypeID { get; set; }

     //[Column(Order = 2)]
     [Display(Name = "Student ID")]
     [Required(ErrorMessage = "Require Student ID")]
     public int StudentID { get; set; }

     [Display(Name = "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")]
     [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; }



public class PropertyType
     public PropertyType() { }

     [Display(Name = "Property Type ID")]
     public int PropertyTypeID { get; set; }

     [Display(Name = "Property Type")]
     [Required(ErrorMessage = "Require Property Type i.e. Flat, House, Studio")]
     public string Type { get; set; }

     [Display(Name = "Title")]
     [Required(ErrorMessage = "Require Property Type Title")]
     public string Title { get; set; }

     public ICollection<Property> Properties { get; set; }
     public ICollection<PropertyRentingPrice> PropertyRentingPrices { get; set; }

8/7/2015 11:37:10 AM

Accepted Answer

Are you connecting to the Default context that includes Identity classes, If so the scaffolding is looking at every class in the identity context, You should try and create a new context for your class or you can place [key] above the user guid.

8/8/2015 5:20:54 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow