I have an MVVM .Net 4.0 WPF application connecting to a database through entity framework. I have a tab control where each tab is a distinct view. Each of these tabs needs to maintain its own DBContext - so that when a tab is selected the previous tab’s context is disposed and the context for the new tab is created and will remain until the user leaves the tab.
This works fine while just navigating the items listed or paging through the items using the data pager control. When a filter is applied, I can navigate away from the tab without issue, but when I navigate back to it, I get an ObjectDisposed exception on the ObjectContext when the onPropertyChanged is called for the bound QueryableEntityCollectionView.
Is there any means of avoiding this exception? I’ve tried a number of different configurations and conditions to eliminate this, but can’t seem to find a solution.
To demonstrate, I’ve attached a simple example that uses the AdventureWorks DB. You’ll have to tweak the connection string in the app.config.
You can browse and navigate between the Products and Employees tabs without issue until you apply a filter to one tab, leave it and then comeback to it.
Thanks for any help you can provide.