值不会在数据库中更新,也不会出错

时间:2017-08-14 14:26:50

标签: asp.net-mvc entity-framework

使用EF6创建MVC5应用程序。我只是尝试使用新值更新db字段。但是,它始终保留旧的价值。我也在SSMS中检查了它,它也显示了旧值。没有显示错误。这是代码....

 private static readonly MyContext Db = new MyContext(); // class-level var
  :
  :
 var EpisodeRecord = Db.Episodes.AsNoTracking().SingleOrDefault(b => b.Id == EpisodeId);
  :
 overallScore = sumOfAllPercentages / ar.Count();

 EpisodeRecord.OverallScore = overallScore;  // I verified before and after and it's ok

 try
  {
     Db.SaveChanges();
  }
 catch (Exception e)
  {
     // code never gets here because there's no error
     Console.WriteLine(e.InnerException.Message);
     throw;
  }

我在设置之前和之后检查了EpisodeRecord.OverallScore的值,并且它正在运行。

任何建议将不胜感激。谢谢!

0 个答案:

没有答案