title: Using DbContext in Parallel
body: <p>Is it possible to use parallelism in Entity Framework's <code>DbContext</code>? Basically I have an application that adds thousands of records for each of the 4 tables that I have. And I am thinking that the best way to optimize it is to have the adding of records done in parallel. </p>
  
  <pre><code>public void Transact()
  {
      var context = new DbContext();
  
      _fooList = new List&lt;Foo&gt;
      { 
          //… Assume that this list contains thousands of objects 
      }
  
      context.Set&lt;Foo&gt;().AddRange(_fooList);
  
      var context1 = new DbContext();
  
      _barList = new List&lt;Bar&gt;
      {
          //… Assume that this list contains thousands of objects
      }
      context1.Set&lt;Bar&gt;().AddRange(_barList);
  
      context.SaveChanges();
      context1.SaveChanges();
  }
  </code></pre>