How to update a nested list in Entity Framework?
I cannot find how to update my EstimateLine
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; }
}
Here is the edit
public ActionResult Edit(EstimateViewModel estimateView)
{
if (ModelState.IsValid)
{
estimate.InjectFrom(estimateView);
var lines = new List<EstimateLine>();
lines.InjectFrom(estimateView.Lines);
estimate.Lines = lines;
db.SaveChanges();
return RedirectToAction("Index");
}
}
Here it does not delete previous line in DB so I got duplicate key error.
How can I tell EF to delete former keys ?
No comments:
Post a Comment