Cannot resolve Symbol ObjectStateManager

北城余情 提交于 2019-12-06 20:14:38

问题


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");
        }

回答1:


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;



回答2:


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



回答3:


Have you added the System.Data.Entity assembly to the project?

Also System.Data.Objects is correct.




回答4:


One additional item to check is that the target .net framework for the project is set to .net 4+.



来源:https://stackoverflow.com/questions/8964680/cannot-resolve-symbol-objectstatemanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!