我遇到ObjectStateManager
的问题。
我是using
System.Data.Entity
和System.Data.Objects
,但它没有显示ObjectStateManager
的定义。
SampleContext db = new SampleContext();
Employees employeeFromDB = db.Employees.Single(x => x.Id == employee.Id);
employeeFromDB.FullName = employee.FullName;
employeeFromDB.Gender = employee.Gender;
employeeFromDB.Age = employee.Age;
employeeFromDB.HireDate = employee.HireDate;
employeeFromDB.Salary = employee.Salary;
employeeFromDB.PersonalWebSite = employee.PersonalWebSite;
db.ObjectStateManager.ChangeObjectState(employeeFromDB, System.Data.EntityState.Modified);
db.SaveChanges();
return RedirectToAction("Details", new {Id = employee.Id});
答案 0 :(得分:0)
来自:Why does the ObjectStateManager property not exist in my db context?
var manager = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager;
答案 1 :(得分:0)
使用此代码:
db.Entry(employeeFromDB).State = EntityState.Modified;
//db.ObjectStateManager.ChangeObjectState(employeeFromDB,System.Data.EntityState.Modified);
db.SaveChanges();