当我尝试创建控制器时,我得到错误调用" EntityType没有定义键" 。这是为什么?
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消息是:
答案 0 :(得分:2)
添加Id的属性,它将是主键,如下所示:
[Key]
public int Id {get;set;}
实际上你还没有在模型中定义主键。
如果 RoomNo 在每一行中始终是唯一的,那么您可以将其设为主键。