title: Multiple LINQ to SQL DataContext in Windows Phone 8
body: <p>I create a mobile commerce in Windows Phone. This apps request JSON data from server and save them into local database. Lets say I have store, product, and category table. For the database, I initialize single DataContext for all CRUD operation, But this application can't run more than 1 operation in one time. For example, when I add some data into product table, I can't read any data from the others. I got Invalid Operation Exception. Then, I try to initialize a DataContext for every operation, I got "An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext" Exception. Is there any solution for my DataContext problem? Here is a sample code of inserting category method.</p>
  
  <pre><code>public bool InsertAll(StoreTable Store, List&lt;Simplz.ViewModel.Category&gt; Categories)
      {
          bool value = true;
          List&lt;CategoryTable&gt; _categories = new List&lt;CategoryTable&gt;();
  
          using (SimplzDataContext DataContext = new SimplzDataContext(ConnectionString))
          {
  
              try
              {
                  foreach (Simplz.ViewModel.Category p in Categories)
                  {
                      if (GetCategory(Store.ID, int.Parse(p.category_id)) == null)
                      {
                          _categories.Add(new CategoryTable(Store, p));
                      }
  
                  }
  
                  DataContext.Categories.InsertAllOnSubmit(_categories);
                  DataContext.SubmitChanges();
              }
              catch (Exception exc)
              {
                  value = false;
                  Debug.WriteLine(exc.Message);
              }
  
              DataContext.Dispose();
          }
  
          return value;
      }
  </code></pre>