C #: How to pass linq objects around

When showing my main window, I create a list of objects from linq-to-sql:

 using (var context = new Data.TVShowDataContext())
 {
    Shows = new ObservableCollection<Data.Show>(context.Shows);
    listShows.ItemsSource = Shows;
 }

Now that I double-clicked an item in my list, I want to use the selected object in the new usercontrol:

 ShowEpList epList = new ShowEpList();
 epList.DataContext = (Data.Show)listShows.SelectedItem;

This now throws an exception:

The System.ObjectDisposedException fix was an unhandled
Message = "Unable to access the remote object. \ R \ nObject: DataContext accessed after Dispose.".
Source = "System.Data.Linq"
ObjectName = "DataContext access after Dispose."

I suppose this happens as a result of linking the list to the list of seasons of the show, and the list of seasons should be populated or something else:

<ListBox Name="listSeasons" ItemsSource="{Binding Seasons}"/>

, , ? DataContext , datacontext, ?

, ....

+5
4

"using" datacontext. , : DataContext

+10

using(), Dispose() , ( ). LINQ to SQL, . Form For m Dispose(bool) ( Designer.cs), .

+5

, DataContext, , , . , DataContext , , , , , .

, , Datacontext, . , - .

+1
source

There are actually good reasons to use these objects besides the datacontext. how to pass objects back to a web service call?

0
source

All Articles