So I have this method in a WebAPI controller.
public HttpResponseMessage Post(Model model)
{
using(var dc = new DataContext())
{
dc.MyData.Add(model);
dc.SaveChanges();
}
//logic that requires the data to be saved first
using(var dc = new DataContext())
{
dc.MyData.Find(model.ID); //this returns null, even tho in the DB I see my model get added to MyData
}
}
The first using
statement saves to the database, however the second using
statement can't find the newly added data. In or normal MVC controller the second using statement works as expected.
Is there a reason the second using
statement can't find the MyData
record from WebAPI?