none
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

Answers

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

    http://blogs.msdn.com/b/adonet/archive/2012/01/12/ef-4-3-beta-1-code-based-migrations-walkthrough.aspx


    Go go Doraemon!

    Friday, June 15, 2012 9:03 AM