【发布时间】:2017-08-07 09:37:42
【问题描述】:
我尝试更新表格列,但失败了。这是我的控制器上的更新代码:
public ActionResult AddDoctorsAppointment(string Start, string End, string Title, int? idPatient)
{
Appointment appointmentDoc = new Appointment()
{
Start_appointment = Start,
End_appointment = End,
Title = Title,
Type_of_appointment = "Doctors",
Patient_Id = idPatient
};
db.Appointments.Add(appointmentDoc);
db.SaveChanges();
return Json(new { Result = "Success", Message = "Saved Successfully" });
}
这里是约会模式
public partial class Appointment
{
public int Id { get; set; }
public string Start_appointment { get; set; }
public string End_appointment { get; set; }
public string Title { get; set; }
public string Type_of_appointment { get; set; }
public Nullable<int> Patient_Id { get; set; }
public virtual Patient Patient { get; set; }
}
当我尝试更新时出现此错误:
我试图找到列名Patient_Id1,但我的项目中没有。
清理和重建没有帮助。我该如何解决这个问题?
【问题讨论】:
-
我假设您使用的是 DB 优先方法。进入您的 .edmx 文件并找到 Appointment 类和 Patient 类的映射。在属性的某处,您将准确地看到哪些属性映射到哪些列,并且能够对其进行更新。
-
当然,您在 EDMX 中存在映射问题(由数字后缀显示,EF 试图避免重复的外键)或同一个 PK 有 2 个不同的 FK(映射两次)。我认为您需要为
Patient类设置ICollection,然后从数据库更新模型。
标签: c# asp.net asp.net-mvc entity-framework