本文介绍了无法解析符号ObjectStateManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到的错误不能解析符号ObjectStateManager 的试图从实体框架4.把它在我的数据库环境时,我找不到其他任何人有这个问题。我已经尝试使用 System.Data这 System.Data.Objects

是否有需要为使用ObjectStateManager来进行特定的实体框架?还是我缺少某种安装包?我使用的数据库优先实体框架。

下面是code这是给我的错误:(7号线)

  [HttpPost]
        公众的ActionResult EditProfile(用户用户)
        {
            如果(ModelState.IsValid)
            {
                db.Users.Attach(用户);
                db.ObjectStateManager.ChangeObjectState(用户,EntityState.Modified);
                db.SaveChanges();
            }
            返回RedirectToAction(档案);
        }


解决方案

我相信你找到了解决办法通过,但现在我遇到了同样的问题,只是现在能够通过改变EntityState线以下,以解决这个问题:

  db.Entry(用户).STATE = EntityState.Modified;

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");
        }
解决方案

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;

这篇关于无法解析符号ObjectStateManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 01:37