1
我试图在EF Code-first中实现多对多。我发现这个代码:EF中的HashSet多对多
public class Student
{
public Student() { }
public int StudentId { get; set; }
[Required]
public string StudentName { get; set; }
public virtual ICollection<Course> Courses { get; set; }
}
public class Course
{
public Course()
{
this.Students = new HashSet<Student>();
}
public int CourseId { get; set; }
public string CourseName { get; set; }
public virtual ICollection<Student> Students { get; set; }
}
我明白,只是一切:
public Course()
{
this.Students = new HashSet<Student>();
}
你能告诉我,为什么这部分是必要的吗?谢谢。