I read the questions regarding to such error message had been raised a few dozen times in SO,
"The ObjectContext instance has been disposed and can no longer be used for operations that require a connection"
however, my scenario might had not been covered.
I am maintaining a legacy WPF app with EF 6, code first and lazy loading. Each window has its own ViewModel which contains a long live DbContext object created in the constructor. So basically the context will buffer all changes until the users press the Save button. Each window contains a master list and details, related to the master/details structure in DB, and the details are loaded through lazy loading.
The ViewModel is wired into the View through such XAML codes:
<UserControl.DataContext>
<vm:CustomersViewModel></vm:CustomersViewModel>
</UserControl.DataContext>
The program basically works well, however, after a few hours of idle, when the user click on the master list to navigate to another record, this error will popup up.
"The ObjectContext instance has been disposed and can no longer be used for operations that require a connection"
The DbContext apparently is not disposed, since it was created in the ViewModel of the windows, and should be disposed only when the window is closed through the IDisposale pattern. I would suspect ObjectContext inside DbContext is disposed after some idle time.
While I understand the common usage of DbContext is to contain in the using clause to make sure short live, however, it will be difficult for me to change to legacy design now. I just wonder if there exist ways to keep DbContext / ObjectContext alive