0

I'm trying to code an web-app which gets one item from one table. This table is shared with another app, which update it while a specific action for a specified controllor is running. This specific action runs in loop until that item has been updated. But, using DataContext as below to get in loop that item and check if it has been updated gets the same recently inserted object without any update, this is the same case when I try to update it manually from SQL Server 2008 to debug my web-app.

private AppDataContext _db = new AppDataContext();
public ActionResult SpecificAction()
    MyClass myObj = new MyClass("op");
    _db.Operations.Add(myObj); // insertion
    _db.SaveChanges();
    while(true){
        var itemm = _db.Itemms.ToList().Where(r => r.date == myObj.date).FirstOrDefault();
        // check, do I need to break?
    }
}

Knowing that I'm using Entity Framework 6.0.2 and ASP.NET MCV 4, how do I refresh that DataContext please?

Thanks a lot!

Tokip
  • 43
  • 1
  • 4
  • Please try to use the search. See for example [Entity Framework Refresh context?](http://stackoverflow.com/questions/20270599/entity-framework-refresh-context). – CodeCaster Mar 22 '14 at 14:12
  • I beleive there is a generic method `DbContext.Refresh`. – Nilesh Mar 26 '14 at 08:48
  • This is answered quite well by looking through the responses to this question: https://stackoverflow.com/questions/20270599/entity-framework-refresh-context – Pow-Ian Nov 13 '17 at 14:15

1 Answers1

0
  • Use a new DbContext each time (my preference)
  • reload entity entry
  • or Google refresh DbContext
phil soady
  • 11,043
  • 5
  • 50
  • 95