title: Using a single context from many threads in Entity Framework 6
body: <p>Is there a way to use one dbContext in a different threads asynchronously?</p>
  
  <pre><code> var context = new Entities();
   Task.Factory.StartNew(() =&gt; context.Companies.Include(x =&gt; x.Address).First());
   Task.Factory.StartNew(() =&gt; context.Companies.Include(x =&gt; x.Owner).First());
   //after some changes...
   context.SaveChanges();
   context.Dispose();
  </code></pre>
  
  <p>The main idea is to save everything at once and if something fail to return all changes.
  In the reality I'm using Unit of Work object which is passed to viewmodel and its child viewmodels so they try to get information asynchronously...  The code above illustrates the problem.
  The code above will throw an exception:</p>
  
  <p>An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code
  The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads concurrently. Note that instance members of DbContext and related classes are not guaranteed to be thread safe.</p>
  
  <p>The main problem is if I'd like to use multiple instances of DbContext each of the Data Transfer Object will contains different information for the fields.
  Any suggestions?
  Thanks!</p>