title: How to force Entity Framework not to lock the database
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/926656/entity-framework-with-nolock">Entity Framework with NOLOCK</a>  </p>
  </blockquote>
  
  
  
  <p>I'm using EF4 and .Net 4 to load some XML from a file into a database.</p>
  
  <p>I have a class the wraps around the ObjectContext and has methods that add the marshalled objects from the XML file to the various EntityCollections that represent my tables.</p>
  
  <p>Each XML file contains around 200,000 objects on average, the wrapper class creates the ObjectContext on construction and stores the reference in a local private class variable which is then used by the methods.</p>
  
  <p>When I have finished creating the entities I call:</p>
  
  <pre><code>entities.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
  </code></pre>
  
  <p>This creates a transaction on the server which is as per EntityFramework design. However this transaction is completely locking down my DB even on tables that are not being added to.</p>
  
  <p>I have tried various things to try and get round this including wrapping save changes in a TransactionScope like this:</p>
  
  <pre><code>using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress,
         new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted }))
         {
              entities.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
  
              transaction.Complete();
         }
  </code></pre>
  
  <p>I have also tried creating the TransactionScope before creating the ObjectContext in an attempt to influence the underlying transaction being used during SaveChanges.</p>
  
  <p>Ideally I would want to load multiple files at once, but this will be impossible if the DB is locked during save changes. </p>
  
  <p>Does anyone know a work around to this issue? Is there away to force the EntityFramework not to use a transaction?</p>
  
  <p>Thanks for any help in advance.</p>
  
  <p>James</p>