Entity framework 创建控制器文件时出错

Entity framework 创建控制器文件时出错,entity-framework,Entity Framework,我使用的是实体框架。我尝试了一切,搜索和添加密钥,但我不明白问题是什么以及如何解决它 public class Reservation { [Key] public int BookingID { get; set; } public int CustomerID { get; set; } public int RoomID { get; set; } public string BookingDate { get; set; } public

我使用的是实体框架。我尝试了一切,搜索和添加密钥,但我不明白问题是什么以及如何解决它

 public class Reservation
{
    [Key]
    public int BookingID { get; set; }
    public int CustomerID { get; set; }
    public int RoomID { get; set; }
    public string BookingDate { get; set; }
    public int Check_In { get; set; }
    public int Check_Out { get; set; }
    public int Adults { get; set; }
    public int Children { get; set; }
    public int NoOfNights { get; set; }

    [ForeignKey("RoomID")]
    public virtual Room Rooms { get; set; }

    [ForeignKey("CustomerID")]
    public virtual CustomerDetails CustomerDetail { get; set; }

    public virtual ICollection<Payment> Payment { get; set; }
}


 public class CustomerDetails
{
    [Key]
    public int CustomerID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int PostCode { get; set; }
    public string State { get; set; }
    public int PhoneNumber { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }

    public virtual ICollection<Reservation> Reservations { get; set; }
}
公共类预订
{
[关键]
public int BookingID{get;set;}
public int CustomerID{get;set;}
public int RoomID{get;set;}
公共字符串BookingDate{get;set;}
在{get;set;}中检查公共int
公共int签出{get;set;}
公共整数{get;set;}
公共int子项{get;set;}
公共整数NoOfNights{get;set;}
[外宾(“室友”)]
公共虚拟房间{get;set;}
[外键(“客户ID”)]
公共虚拟客户详细信息客户详细信息{get;set;}
公共虚拟ICollection付款{get;set;}
}
公共类客户详细信息
{
[关键]
public int CustomerID{get;set;}
公共字符串名{get;set;}
公共字符串LastName{get;set;}
公共整数邮政编码{get;set;}
公共字符串状态{get;set;}
公共int电话号码{get;set;}
公共字符串电子邮件{get;set;}
公共字符串密码{get;set;}
公共虚拟ICollection保留{get;set;}
}

所有表都需要主键,或者您不能使用实体框架。

您真的确定所有实体都有主键吗?您是如何通过实体类型配置或数据代理设置这些主键的?我不知道如何向您描述它。我做了模型课。其中我给了他们一个[key]属性。key属性是DataAttribute。该错误表示有许多实体在Id属性(或其他键属性名称)中没有键属性(如果可能),然后显示一些模型类作为示例