Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8380725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:31:48+00:00 2026-06-09T16:31:48+00:00

I have done this before, but for some reason cannot get it to work

  • 0

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.

EF Working

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

EF Not working

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"));
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:31:50+00:00Added an answer on June 9, 2026 at 4:31 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have done this several times before but for some reason I can't get
I have done this before and for some reason I just can't get it
I have done this before but I forgot where in my app I have
I am not an expert in Git, but I have seen this done before
I've never done this before. The website I have just built is the second
This is weird ... done updates loads of times before but cannot spot why
Before someone tells me this cannot be done, I have done plenty of research
I've done this before somewhere I'm sure of it! I have a SQL Server
Ok, I have done plenty of research on this topic before asking the question,
I have done this operation millions of times, just using the + operator! I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.