EF5 Code: Many to Many with Migration

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.

Ef working

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

EF Not working

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"));
    }
+5
source share
1 answer

M2M EF5.0RC , . , , . SQL .

, EF5.0 RTM, .

+3

All Articles