UPDATE语句与FOREIGN KEY约束冲突

时间:2013-01-29 01:45:00

标签: c# asp.net-mvc entity-framework

我收到此错误

  

UPDATE语句与FOREIGN KEY约束冲突   “FK_dbo.Refills_dbo.Patients_PatientId”。冲突发生在   数据库“SpX.Models.Context”,表   “dbo.Patients”,列'Id'。声明已经终止。

public ActionResult Details(Patient patient)
{

    Patient p = db.Patients.Find(patient.Id);


    db.Entry(p).State = EntityState.Modified;
    db.Entry(p).CurrentValues.SetValues(patient);

    foreach (var refill in patient.Refills)
    {
        var r = db.Refills.Find(refill.Id);

        db.Entry(r).State = EntityState.Modified;
        db.Entry(r).CurrentValues.SetValues(refill);

    }


    db.SaveChanges();



    return View(p);
}

如何更新补充部分?

0 个答案:

没有答案
相关问题