title: One-to-many relationships with code-first Entity Framework
body: <p>I'm trying to set up a one-to-many relationship (I think) using code-first Entity Framework.</p>
  
  <p>I have a <code>ProductListing</code> object which can have many associated <code>Country</code> objects. I had thought that I had set this up correctly, but my <code>Countries</code> table has a reference column for <code>ProductListing</code>. This is a problem because although a <code>ProductListing</code> can have a relationship with <code>Country</code>, the <code>Country</code> object should not be aware or reliant upon the <code>ProductListing</code> object.</p>
  
  <p><strong>ProductListing</strong></p>
  
  <pre><code>public class ProductListing : AuditedEntity&lt;long&gt;
  {
      public long ProductId { get; set; }
      public Product Product { get; set; }
  
      public long RetailerId { get; set; }
      public Retailers.Retailer Retailer { get; set; }
  
      public ICollection&lt;Countries.Country&gt; Countries { get; set; }
  
      public bool IsOfficial { get; set; }
  
      public decimal CurrentPrice { get; set; }
      public decimal PreviousPrice { get; set; }
  
      public string ListingUrl { get; set; }
      public string AffiliateString { get; set; }
  
      public DateTime? ReleaseDate { get; set; }
      public DateTime? ShipDate { get; set; }
      public DateTime? ExpiresDate { get; set; }
  }
  </code></pre>
  
  <p><strong>Country</strong></p>
  
  <pre><code>public class Country : AuditedEntity&lt;long&gt;
  {
      [Required]
      [StringLength(ShylockConsts.MaxNameLength)]
      public virtual string Name { get; set; }
  
      [Required]
      [StringLength(ShylockConsts.MaxIsoLength)]
      public virtual string IsoCode { get; set; }
  }
  </code></pre>