title: EF4 How to clear DbContext internal state?
body: <p>How can I tell an EF4 DbContext to clear its internal cache/state?</p>
  
  <p>I have a database updater program which executes a large number of inserts on a variety of tables via EF4 within a transaction. I find the inserts to a common Permissions table get slower and slower as the update proceeds.</p>
  
  <p>There are the following constraints at play:</p>
  
  <p>1) Everything must occur within a single (giant) transaction.</p>
  
  <p>2) Can't introduce dependency on MSDTC - so I can't have a cross-connection transaction.</p>
  
  <p>3) Can't seem to open a new DbContext for a SqlConnection which is already open - encounters "EntityConnection can only be constructed with a closed DbConnection" error. (note that I am already sharing a SqlConnection between multiple DbContext's, but only opening the connection after they are all initialized)</p>
  
  <p>Given these constraints, I can't create a new DbContext for each chunk of the work, as it breaks the transaction.</p>
  
  <p>I've satisfied these functional constraints, but the performance is poor. I suspect the DbContext is struggling to handle the volume of data being inserted into the DbSet.</p>
  
  <p>How can I tell the DbContext to reset its internal cache (eg. the rows I inserted recently and don't care about any more)?</p>