title: How to update a nested list in Entity Framework?
body: <p>I cannot find how to update my EstimateLine  </p>
  
  <pre><code>public class EstimateLine
  {
      [Key]
      [Column(Order = 0)]
      public virtual int EstimateId { get; set; }
  
      [Key]
      [Column(Order = 1)]
      public virtual int LineId { get; set; }
  
      public virtual float Price { get; set; }
  }
  </code></pre>
  
  <p>Here is the Estimate class</p>
  
  <pre><code>public class Estimate
  {
      public virtual int EstimateId { get; set; }
  
      public virtual float TotalPrice { get; set; }
  
      public virtual IList&lt;EstimateLine&gt; Lines { get; set; }
  ]
  </code></pre>
  
  <p>Here is the edit </p>
  
  <pre><code>public ActionResult Edit(EstimateViewModel estimateView)
  {
          var estimate = db.Estimates.FirstOrDefault(e =&gt; e.EstimateId == estimateView.EstimateId);
  
          if (ModelState.IsValid)
          {
              estimate.InjectFrom(estimateView);
  
              var lines = new List&lt;EstimateLine&gt;();
              lines.InjectFrom(estimateView.Lines);
  
              estimate.Lines = lines;
  
              db.SaveChanges();
              return RedirectToAction("Index");
  
          }
  }
  </code></pre>
  
  <p>Here it does not delete previous line in DB so I got duplicate key error. How can I tell EF to delete former estimate lines ?</p>