Entity Framework not refreshing the database

Viewed 43

I need to update old path in the database to the new one. When I run the code, I can see the new path updates in the database but when I try to get it from the database, I get back the old path (like I didn't change it).

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();
    }
}

Other place in the code

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