Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve Symbol ObjectStateManager

I have getting an Error of "Cannot Resolve Symbol ObjectStateManager" when trying to call it on my Database context from Entity Framework 4. I can't find anyone else having this issue. I have tried using System.Data and System.Data.Objects.

Is there a specific Entity Framework that needs to be made in order to use the ObjectStateManager? Or Am I missing some sort of install package? I am using Database First Entity Framework.

Here is the code it is giving my error: (Line 7)

[HttpPost]
        public ActionResult EditProfile(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Attach(user);
                db.ObjectStateManager.ChangeObjectState(user, EntityState.Modified);
                db.SaveChanges();
            }
            return RedirectToAction("Profile");
        }
like image 590
Rizowski Avatar asked Jan 22 '12 21:01

Rizowski


2 Answers

I am sure you found a solution by now but I ran into the same issue just now and was able to resolve it by changing the EntityState line to the following:

db.Entry(user).State = EntityState.Modified;
like image 107
Paul King Avatar answered Sep 17 '22 18:09

Paul King


Probably you are using code first EF. In this case you have to revert yours code to explicit implemenatation of IObjectContextAdapter, i.e.

((IObjectContextAdapter)db).ObjectContext.ObjectStateManager
like image 25
Vitaliy Kalinin Avatar answered Sep 20 '22 18:09

Vitaliy Kalinin