I have done this before, but for some reason cannot get it to work in EF5.
Usually it just automatically picks up when I have many to many relationships like this one…
public class Beer
{
public int Id { get; set; }
public virtual ICollection<Restaurant> Restaurants { get; set; }
}
public class Restaurant
{
public int Id { get; set; }
public virtual ICollection<Beer> Beers { get; set; }
}
I am wanting a RestaurantsBeers table or whatever with just RestaurantId and BeerId.
When I create it using the normal Code First way by just running the application it works.

Using migrations though, it won’t create that table.

I ran Enable-Migrations then Add-Migration FirstDb and finally Update-Database… No dice…
Also tried this…
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Beer>()
.HasMany(b => b.Restaurants)
.WithMany(a => a.Beers)
.Map(m => m.MapLeftKey("BeerId")
.MapRightKey("RestaurantId")
.ToTable("BeersRestaurants"));
}
Migrations to create a new M2M relationship are not supported yet in EF5.0RC per my experience trying to track down the same issue. Thus why it will work on standard DB creation but doesn’t work with Migration features. You can export the create SQL from the standard code first database initialization and run it manually on the migration for now.
This should be resolved when EF5.0 goes RTM but for now we have to wait it out.