创建控制器文件时出错

时间:2017-04-21 18:22:27

标签: entity-framework

我正在使用Entity Framework。我已经尝试了所有内容,搜索和添加密钥,但我enter image description here无法理解问题是什么以及如何解决问题。

 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; }
}

enter image description here

1 个答案:

答案 0 :(得分:0)

所有表都需要主键,否则您无法使用实体框架。