使用实体框架的API,我不断遇到以下两种方式来映射多对多关系?我从未使用过第二个选项...有什么区别?
选项1:
modelBuilder.Entity<Student>()
.HasMany( p => p.Lessons)
.WithMany();
Run Code Online (Sandbox Code Playgroud)
选项2:
modelBuilder.Entity<Student>()
.HasMany(p => p.Lessons)
.WithMany()
.Map(m =>
{
m.MapLeftKey("Id");
m.MapRightKey("Id");
m.ToTable("StudentAndLessons");
});
Run Code Online (Sandbox Code Playgroud)
这到底是什么MapLeftKey和MapRightKey做什么?您何时使用它并获得什么好处?