title: Why Entity Framework locks tables on save?
body: <p>I have a transaction which inserts huge amount of data (over 5000+ records) into 3 tables (so it takes a while), which is OK, but I noticed something disturbing. All 3 tables seems to be locked during that process.</p>
  
  <p>Insert transaction:</p>
  
  <pre><code>using(var db = new MyEntities())
  {
      using (var tr = db.Database.BeginTransaction())
      {
           // blah, blah, a lot of entities to create, **some custom SQL, bulk inserts** etc.
  
           db.SaveChanges();
           tr.Commit();
      }
  }
  </code></pre>
  
  <p>I'am unable to read during save from tables whether it's EF or raw SQL query. But selecting with (NOLOCK) works:</p>
  
  <pre><code>SELECT * FROM Table1 WITH (NOLOCK)
  </code></pre>
  
  <p>First of all I'd like to know what is actually happening? Is it just the "natural" behaviour and tables are locked no matter what or maybe it's lock escalation or something else.</p>
  
  <p>Second, is it possible to disable locks on the level of insert transaction? Or do I have to add "WITH (NOLOCK)" to all SELECT queries?</p>
  
  <p>Third, is it possible to make SELECT queries return data during saving, but ONLY records from commited transactions (for ex. my insert transaction already added 2000 records, 3000 pending, I make a select query and it return all records except those 2000, which are not yet commited).</p>