无法解析符号ObjectStateManager
当我尝试从 Entity Framework 4 的数据库上下文中调用它时,出现“无法解析符号 ObjectStateManager”错误。我找不到其他人遇到此问题。我尝试过使用System.Data和System.Data.Objects。
是否需要创建特定的实体框架才能使用 ObjectStateManager?或者我是否缺少某种安装包?我正在使用数据库第一实体框架。
这是给出错误的代码:(第 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");
}
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");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我确信您现在已经找到了解决方案,但我刚才遇到了同样的问题,并且能够通过将 EntityState 行更改为以下内容来解决它:
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:
可能您正在使用代码优先 EF。在这种情况下,您必须将代码恢复为 IObjectContextAdapter 的显式实现,即
Probably you are using code first EF. In this case you have to revert yours code to explicit implemenatation of IObjectContextAdapter, i.e.
您是否已将 System.Data.Entity 程序集添加到项目中?
System.Data.Objects
也是正确的。Have you added the
System.Data.Entity
assembly to the project?Also
System.Data.Objects
is correct.要检查的另一项是项目的目标 .net 框架是否设置为 .net 4+。
One additional item to check is that the target .net framework for the project is set to .net 4+.