使用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的值,并且它正在运行。
任何建议将不胜感激。谢谢!