Using Entity Framework's API I keep coming across the following two ways to map many to many relationships? I have never used the second option... what is the difference?
Option 1:
modelBuilder.Entity<Student>()
.HasMany( p => p.Lessons)
.WithMany();
Option 2:
modelBuilder.Entity<Student>()
.HasMany(p => p.Lessons)
.WithMany()
.Map(m =>
{
m.MapLeftKey("Id");
m.MapRightKey("Id");
m.ToTable("StudentAndLessons");
});
What exactly does MapLeftKey
and MapRightKey
do? When would you use it and what benefits are gained?