嗨亲爱的所有EF / MVC4开发人员;
编辑控制器时遇到问题,它显示以下错误:
无法隐式转换类型System.Data.EntityState'至 ' System.Data.Entity.EntityState' 。存在显式转换(是 你错过了一个演员?)
public ActionResult Edit(int id, Employee employee)
{
try
{
using(InformationContext context = new InformationContext())
{
context.Entry(employee).State = System.Data.EntityState.Modified;
context.SaveChanges();
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
答案 0 :(得分:0)
如果您使用的是EF 6或从EF 5移动到EF 6, 别忘了更改System.Data.Entity.EntityState而不是System.Data.EntityState。 当您的代码引用Entity Framework 6但您的代码在Entity Framework 5上时,这是一个错误。