title: Entity Framework and adding a reference / entry to a lookup table
body: <p>I have a project where I use a lookup table to link two tables together:</p>
  
  <pre><code>Day         WeatherLookUp       Weather
  ---         -------------       -------    
  ID (PK) --&gt; DayID            |- ID (PK)
              WeatherID    &lt;---|  Description
  </code></pre>
  
  <p>This allows me to specify multiple weather conditions for a day. </p>
  
  <p>I can read from this without any issues but my problem is when I come to insert a link between the Day and the Weather table. I created the WeatherLookup table's two columns as the compound primary key of the table and as a result EF doesn't allow me to do a direct insert into the WeatherLookup table.</p>
  
  <p>I had thought I just needed to add a Weather entry like this:</p>
  
  <pre><code>myDay.Weather.Add(new Weather { ID = 2 } );
  </code></pre>
  
  <p>...but EF thinks I'm trying to add a new weather type. </p>
  
  <p>I'm sure I'm missing something obvious but I can't work out what, do I need to be using <code>Attach()</code> in some way? </p>