映射多对多与单个模型的关系

Mapping Many to many relationship with single model

我的模型

public class Student
    {
        public int id{ get; set; }

        public string Name{ get; set; }

        public string Qualification{ get; set; }

   }

在我的项目中,我试图创建学生的合作伙伴,一个学生可以与任意数量的学生合作。我知道我可以通过创建另一个像这样的模型来实现这一点

 public class Partners
    {

        public string student1ID{ get; set; }

        public string student2ID{ get; set; }

   }

并插入值,但只想知道是否有任何其他方法可以使用虚拟列表<>等实现此目的

要使每个学生都有一个或多个伙伴的关系,您可以这样做:

public class Student
{
    public int Id{ get; set; }
    public string Name{ get; set; }
    public string Qualification{ get; set; }
    public virtual ICollection<Partner> Partners{ get; set; }     
}

public class Partner
{
    public int Id{ get; set; }
    public virtual Student Student{ get; set; }
}