我找不到如何更新我的 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; }
}
这是估计类
public class Estimate
{
public virtual int EstimateId { get; set; }
public virtual float TotalPrice { get; set; }
public virtual IList<EstimateLine> Lines { get; set; }
]
这是编辑
public ActionResult Edit(EstimateViewModel estimateView)
{
var estimate = db.Estimates.FirstOrDefault(e => e.EstimateId == estimateView.EstimateId);
if (ModelState.IsValid)
{
estimate.InjectFrom(estimateView);
var lines = new List<EstimateLine>();
lines.InjectFrom(estimateView.Lines);
estimate.Lines = lines;
db.SaveChanges();
return RedirectToAction("Index");
}
}
在这里它不会删除数据库中的前一行,所以我得到了重复键错误。我怎样才能告诉 EF 删除以前的估计行?