我有两张桌子:(1)学生和(2)课程,我还有一个名为(3)StudentCourse的联接表。 相关数据:
public class Student
{
private ICollection<Course> _courses
public int Id {get;set;}
public Student(){
_courses = new Collection<Course>();
}
public ICollection<Course> Courses{
get {return _courses;}
set { _courses = value;}
}
}
public class Course
{
private ICollection<Student> _students
public int Id {get;set;}
public Course(){
_students = new Collection<Student>();
}
public ICollection<Student> Students{
get {return _students;}
set { _students = value;}
}
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Course>()
.HasMany<Student>(r => r.Students)
.WithMany(u => u.Courses)
.Map(m =>
{
m.ToTable("StudentCourse");
m.MapLeftKey("CourseId");
m.MapRightKey("StudentId");
});
}
我的上下文构造函数有:Configuration.LazyLoadingEnabled = false;
当我通过迁移种植我的课程和学生表时,StudentCourse表没有填充。
我错过了什么?
答案 0 :(得分:0)
我的不好,我没有将CourseCollection添加到Student类