title: Representing a Junction Table in Entity Framework
body: <p>I am creating a schema where the following logic applies:</p>
  
  <ul>
  <li>A <code>String</code> can belong to multiple locations.</li>
  <li>Multiple <code>Locations</code> can have multiple <code>String</code>, or no
  <code>String</code>.</li>
  <li>The <code>DateTime</code> (As <code>DateScraped</code>) at which the relationship between <code>Location</code> and <code>String</code> was formed must be recorded.</li>
  </ul>
  
  <p>Basically, I've mapped the relationship as a <strong>many-to-many</strong> relationship using a junction table like so:</p>
  
  <p><a href="https://i.stack.imgur.com/6PDkW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6PDkW.png" alt="sqldbm"></a></p>
  
  <p>In mapping the chart in Code First EF6 (Using SQLite), I have the following objects:</p>
  
  <pre><code>public class Location
  {
      [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public long LocationId { get; set; }
  
      [Required]
      public string Country { get; set; }
  
      [Required]
      public string CityOrProvince { get; set; }
  
      [Required]
      public string PlaceOrCity { get; set; }
  
      [Required]
      public string PostalCode { get; set; }
  }
  
  public class String
  {
      [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public long StringId { get; set; }
  
      [Required]
      public string SearchString { get; set; }
  }
  
  public class LocationStringMapping
  {
      [Required]
      public string LocationId { get; set; }
  
      [Required]
      public string StringId { get; set; }
  
      [Required]
      public DateTime DateScraped { get; set; }
  }
  </code></pre>
  
  <p>I've based what I've done so far on conjecture as I cannot seem to find any concrete information on how a relationship such as this must be built. Normally I'd use a junction table, but that is in vanilla SQL. Is the implementation different in EF?</p>
  
  <p>Am I going to have to cumbersomely manage the <code>LocationStringMapping</code> table by hand or is there some kind of implicit relationship model I don't know about? </p>