Jika ada tabel many-to-many, dengan tabel perantara yang tidak memiliki id, perlu penanganan khusus pada DbContext. Contoh penanganan sbb:
[code language=”csharp”]
public class SchoolContext : DbContext
{
public DbSet<Course> Courses { get; set; }
public DbSet<Person> People { get; set; }
public SchoolContext()
: base("MyDb")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Course>().
HasMany(c => c.Students).
WithMany(p => p.CoursesAttending).
Map(
m =>
{
m.MapLeftKey("CourseId");
m.MapRightKey("PersonId");
m.ToTable("PersonCourses");
});
}
}
[/code]
http://www.codeproject.com/Articles/234606/Creating-a-Many-To-Many-Mapping-Using-Code-First