0
私は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; }
}
本当にすべてのエンティティにプライマリキーがあることは確かですか?エンティティタイプ構成またはデータ属性によって、これらの主キーをどのように設定しましたか? –
私はそれをあなたに説明する方法を知らない。私はモデルクラスを作った。そこに私は[key]属性を与えています。 – Ariba21
Key属性はDataAttributeです。エラーは、Idプロパティ(または他のキープロパティ名)にKey属性を持たない多くのエンティティがあると言います。可能であれば、 –