title: EF One To Many Bug
body: <p>Can anyone tell me what I have done wrong? </p>
  
  <p>When it gets to the db.SaveChanges() I get the following error. </p>
  
  <p>One or more validation errors were detected during model generation: EntityType 'Order' has no key defined. Define the key for this EntityType. Orders1: EntityType: EntitySet 'Orders1' is based on type 'Order' that has no keys defined.</p>
  
  <p>As you can see I am not trying to do anything complex but, can't see what I have missed.</p>
  
  <p>Db Context:</p>
  
  <pre><code>public class NewOrderContext : DbContext
  {
      public DbSet&lt;NewServices.OrderEntity&gt; Orders { get; set; }
      public DbSet&lt;NewServices.OrderLineEntity&gt; OrderLines { get; set; }
  }
  </code></pre>
  
  <p>OrderEntity:</p>
  
  <pre><code>[Table("Order")]
  public class OrderEntity
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
      public int State { get; set; }
      public decimal Handling { get; set; }
      public int BuyerId { get; set; }
      public string ShippingAddresseeName { get; set; }
      public string ShippingAddressLine1 { get; set; }
      public string ShippingAddressLine2 { get; set; }
      public string ShippingCity { get; set; }
      public string ShippingRegion { get; set; }
      public string ShippingCountry { get; set; }
      public string ShippingPostalCode { get; set; }
      public DateTime Created { get; set; }
      public string TrackingRef { get; set; }
      public int OfferId { get; set; }
  
      public virtual ICollection&lt;OrderLineEntity&gt; OrderLines { get; set; }
  }
  </code></pre>
  
  <p>OrderLineEntity:</p>
  
  <pre><code>[Table("OrderLine")]
  public class OrderLineEntity
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
      public string PartCode { get; set; }
      public decimal PartPrice { get; set; }
      public int OrderId { get; set; }
  
      [ForeignKey("OrderId")]
      public virtual Order Order { get; set; }
  }
  </code></pre>
  
  <p>I'm using the above in the following method snippet:</p>
  
  <pre><code>using (var db = new NewOrderContext())
  {
      var order = new OrderEntity
                  {
                      OfferId = offerId,
                      ....
                      Created = DateTime.UtcNow
                  };
  
  
      var lines = new List&lt;OrderLineEntity&gt;
                  {
                      new OrderLineEntity
                      {
                          PartCode = offer.PartCode,
                          PartPrice = offer.PriceOffered
                      }
                  };
  
      order.OrderLines = lines;
      db.Orders.Add(order);
      db.SaveChanges();
   ......
  }
  </code></pre>