title: How to properly use a LINQ2SQL DataContext object; creating anew each use causes headaches
body: <p>So, in learning LINQ2SQL (don't tell me it's a dead technology please, I'm not switching to EF for simple applications) I have read numerous times that the DataContext class is meant to be created and destroyed frequently.  Great, a lightweight object that I can use to access my database.  However, in practice this seems to cause nothing but trouble.  For example, if I load up a DataGrid like so changes to entity objects don't seem to be tracked and calling DataContext.SubmitChanges has no effect:</p>
  
  <pre><code>void LoadUI()
  {
      using( var db = new TestDataContext() )
      {
          // use DataLoadOptions.LoadWith&lt;T&gt; if we need 
          // access to foreign key/ deferred objects.
          masterGrid.ItemsSource = db.Customers.ToList();
          detailsGrid.ItemsSource = // this is always set to a collection of Settings
                                    // for the currently selected user in masterGrid.
                                    // just a simple foreign key relationship
      }
  }
  
  void UpdateName( string newName )
  {
      using( var db = new TestDataContext() )
      {
          var customer = ((Customer)masterGrid.SelectedItem);
          customer.Name = newName;
          db.SubmitChanges() // !!! database is not updated !!!    
      }
  }
  </code></pre>
  
  <p>So what gives?  Creating a new DataContext object when accessing the DB seems to be the accepted/preferred practice, yet it doesn't seem to work in the most trivial of cases.  It appears that object tracking doesn't work in this scenario, so how could one possibly use the DataContext class like this in practice?  Am I missing something here? (Note: I really do hope I am actually missing something simple.  </p>
  
  <p>I have to assume that is the case, but I don't know what the answer is yet.  Currently I am just keeping a single DC around for the life of the app, which I know is probably not a good idea).  Thanks in advance for any advice you can offer.</p>
  
  <p>BTW, if any of you know of a comprehensive article/serie4s of articles which describe the ins-and-outs of the DataContext class I would love to read it.  I haven't found any examples which go beyond trivial updates/inserts/deletes.</p>