使用实体框架更新并不反映我的数据库表

时间:2018-03-09 08:05:30

标签: asp.net asp.net-mvc asp.net-mvc-4 web entity-framework-6

我是Entity Framework的新手,并编写了一个更新特定列TStatus的函数。

以下是我尝试执行的内容:

public ActionResult UpdateTStatus(int ICCID) 
{
        using (var db = new MyDBContext())
        {
            var result = db.INTERVIEW_AGENT_CALL_CENTERS.Where(g => g.Id == ICCID).FirstOrDefault();

            if (result != null)
            {
                result.TStatus= 10;
                db.Entry(result).State = EntityState.Modified;
                db.SaveChanges();

                return Content("Result = "+result.TStatus);
            }
            else
            {
                return Content("An Error");
            }
        }

        return View();
    }

每当我执行该方法并在SQL Server上运行直接查询时,我都会获得TStatus的旧值。

0 个答案:

没有答案