且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在使用实体框架code首先两个实体之间的多个一对许多关系

更新时间:2022-11-04 18:43:53

尝试添加2学生您的评论类,例如:

Try to add 2 Students in your Review class, for example:

[Table("tb_review")]
public class Review
{    
    [Key]
    public int id { get; set; }
    public string message { get; set; }
    public Student student{ get; set; } // review of which student
    public Student reviewer{ get; set; } // whom send the review
} 

和你的学生类应该是这样的:

And your Student class should be like this:

[Table("tb_student")]
public class Student
{    
    [Key]
    public int id { get; set; }
    public string name { get; set; }
    [InverseProperty("student")]
    public List<Review> reviewAbout{ get; set; }
    [InverseProperty("reviewer")]
    public List<Review> reviewBy{ get; set; }
}