نوشته شده توسط
ali_md110
نحوه تعریف کلید خارجی اشتباه هست
[System.ComponentModel.DataAnnotations.Schema.Forei gnKey("UserSend")]
این UserSend کجاست؟
یا UserGet وجود ندارد
در ضمن InverseProperty در جدول فرزند الزامی ندارد تعریف کنید و اینجا هم باز اشتباه تعریف کردید
ببخشید یادم رفته بود اونا رو هم بنویسم:
public class tblMessage {
public tblMessage()
{
}
[System.ComponentModel.DataAnnotations.Schema.Datab aseGenerated(System.ComponentModel.DataAnnotations .Schema.DatabaseGeneratedOption.None)]
[System.ComponentModel.DataAnnotations.Key]
[System.ComponentModel.DataAnnotations.Required]
public int ID { get; set; }
//[System.ComponentModel.DataAnnotations.Schema.Forei gnKey("tblUser")]
[System.ComponentModel.DataAnnotations.Required]
public int UserGet { get; set; }
//[System.ComponentModel.DataAnnotations.Schema.Forei gnKey("tblUser")]
public int? UserSend { get; set; }
[System.ComponentModel.DataAnnotations.Schema.Inver seProperty("tblMessages")]
[System.ComponentModel.DataAnnotations.Schema.Forei gnKey("UserSend")]
public virtual tblUser tblUser { get; set; }
[System.ComponentModel.DataAnnotations.Schema.Inver seProperty("tblMessages2")]
[System.ComponentModel.DataAnnotations.Schema.Forei gnKey("UserGet")]
public virtual tblUser tblUser2 { get; set; }
}
public class tblUser
{
public tblUser()
{
}
[System.ComponentModel.DataAnnotations.Schema.Datab aseGenerated(System.ComponentModel.DataAnnotations .Schema.DatabaseGeneratedOption.None)]
[System.ComponentModel.DataAnnotations.Required]
[System.ComponentModel.DataAnnotations.Key]
public int ID { get; set; }
[System.ComponentModel.DataAnnotations.Schema.Inver seProperty("tblUser")]
public virtual List<tblMessage> tblMessages { get; set; }
[System.ComponentModel.DataAnnotations.Schema.Inver seProperty("tblUser2")]
public virtual List<tblMessage> tblMessages2 { get; set; }
}
ببخشید من تازه asp.net mvc رو یاد میگیرم. کلاس فرزند کدومه؟
آیا نحوه تعریف کلید خارجی اشتباه است؟
مگه نگفتید الزامی ندارد به تعریف Inversproperty در کلاس فرزند، پس چرا در صورت تعریف گفتید اشتباه است؟