实体框架未刷新数据库

时间:2017-09-28 17:45:25

标签: c# entity-framework

我需要将数据库中的旧路径更新为新路径。当我运行代码时,我可以看到数据库中的新路径更新,但是当我尝试从数据库中获取它时,我回到旧路径(就像我没有更改它)。

public void UpdateReportPath(string oldPath,string newPath)
{
    using (var context = new Db())
    {
        var reports = context.Report.Where(r => r.ReportId > 0).ToList();

        foreach (var report in reports)
        {
            report.ReportFullPath = report.ReportFullPath.Replace(oldPath, newPath);
        }

        context.SaveChanges();
    }
}

代码中的其他位置

var fullPath = Report.ReportFullPath;     // I get old path

0 个答案:

没有答案