I have done this before, but for some reason I can't get it to work in EF5.
Usually it just gets automatically selected when I have many different relationships, such as this ...
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 want the table "RestaurantsBer" or something else with the help of "Restaurants" and "Take".
When I create it using regular First way code, just by running the application, it works.

However, using migrations, it will not create this table.

I ran Enable-Migrations, then, Add-Migration FirstDband finally Update-Database... No dice ...
And tried it ...
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"));
}
source
share