c# - Validation error: EntityType has no key defined -


when try create controller error call " entitytype has no key defined" . why that?

using system; using system.collections.generic; using system.data.entity; using system.linq; using system.web; using system.componentmodel.dataannotations;  namespace hotelmanagementsystem.models {     public class room     {         public int roomno { get; set; }         public string packageid { get; set; }         public string resid { get; set; }         public bool tv { get; set; }         public bool wifi { get; set; }         public bool internet { get; set; }         public bool telephone { get; set; }         public bool ac { get; set; }         public bool bathroom { get; set; }         public bool fridge { get; set; }         public bool homethearter { get; set; }     }     public class roomcontext : dbcontext {     public dbset<room/*table name*/> hotelmanagementsystem /*data base name */ { get; set; } } } 

erroe message :enter image description here

add property of id primary key this:

[key] public int id  {get;set;} 

actually have not defined primary key in model.

if roomno unique in each row, can make primary key.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -