EF Migrations will not create a Many to Many table. RRS feed

  • Question


    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.

    The thing is, it works when allowing Code First to do its default thing just running the project.

    However, when I Enable-Migrations, Add-Migration FirstDb, and Update-Database, it will not create the correct table.

    I created a blank MVC4 application to test this.

    • Edited by jcreamer898MVP Thursday, June 14, 2012 3:29 AM Update code, add images
    Thursday, June 14, 2012 3:25 AM


  • You need to write code manually, please refer this link.

    Go go Doraemon!

    Friday, June 15, 2012 9:03 AM