How to have multiple one-to-many relations between two entities using Entity Framework Code First

前端 未结 2 1485
粉色の甜心
粉色の甜心 2021-01-26 00:05

Below is a simple approach to save relational database records which is working perfectly fine. I have doubt on one scenario. Before that i need to know the way i am approaching

2条回答
  •  清歌不尽
    2021-01-26 00:52

    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 reviewAbout{ get; set; }
        [InverseProperty("reviewer")]
        public List reviewBy{ get; set; }
    } 
    

提交回复
热议问题