title: Entity framework large data set, out of memory exception
body: <p>I am working the a very large data set, roughly 2 million records. I have the code below but get an out of memory exception after it has process around three batches, about 600,000 records. I understand that as it loops through each batch entity framework lazy loads, which is then trying to build up the full 2 million records into memory. Is there any way to unload the batch one I've processed it?</p>
  
  <pre><code>ModelContext dbContext = new ModelContext();
  IEnumerable&lt;IEnumerable&lt;Town&gt;&gt; towns = dbContext.Towns.OrderBy(t =&gt; t.TownID).Batch(200000);
  foreach (var batch in towns)
  {
      SearchClient.Instance.IndexMany(batch, SearchClient.Instance.Settings.DefaultIndex, "Town", new SimpleBulkParameters() { Refresh = false });
  }
  </code></pre>
  
  <p>Note: The Batch method comes from this project: <a href="https://code.google.com/p/morelinq/">https://code.google.com/p/morelinq/</a></p>
  
  <p>The search client is this: <a href="https://github.com/Mpdreamz/NEST">https://github.com/Mpdreamz/NEST</a></p>