Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was finally able to get the tables created correctly, using the link i added to my updated question, but still not really sold on the solution. To my Db Context class I added the method [protected override void OnModelCreating(DbModelBuilder modelBuilder)].</p> <pre><code>public class MyTesterContext : DbContext { public MyTesterContext () : base("name=MyTesterContext ") { } public DbSet&lt;Trip&gt; Trips { get; set; } public DbSet&lt;Location&gt; Locations { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity&lt;Trip&gt;(). HasMany(t =&gt; t.Itinerary). WithMany(l =&gt; l.Trips). Map( m =&gt; { m.MapLeftKey("TripID"); m.MapRightKey("LocationID"); m.ToTable("TripLocations"); }); } } </code></pre> <p>The new database now looks like the following:</p> <pre> Tables Locations PK ID (int) Name (varchar) TripLocations TripID (int) LocationID (int) Trips PK ID (int) Name (varchar) Begin (datetime) End (datetime) HomeCountry_ID (int) </pre> <p>In the code project discussion it says: <br/> <a href="http://www.codeproject.com/Articles/234606/Creating-a-Many-To-Many-Mapping-Using-Code-First" rel="nofollow">http://www.codeproject.com/Articles/234606/Creating-a-Many-To-Many-Mapping-Using-Code-First</a></p> <blockquote> <p>So we have a small problem with existing relation tables. We can solve the problem by overriding the OnModelCreating method and adding the mapping using the Code First Fluent API. </p> </blockquote> <p>Since I did not have an existing relation table, I honestly did not think this step would be required, but I have been unable to find any other way to get this to create the proper table structure. Hopefully as I become more familiar with the technology, I can find a way around requiring the need to override the OnModelCreating method. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload