title: EF CF slow on generating insert statements
body: <p>I have  project that pull data from a service (return xml) which deserialize into objects/entities.</p>
  
  <p>I'm using EF CF and testing is working fine until it come to big chuck of data, not too big, only 150K records, I use SQL profile to check the SQL statement and it's really fast, but there is a huge slow issue with generating insert statement.</p>
  
  <p>simply put, the data model is simple, class Client has many child object set (5) and 1 many-to-many relationship.</p>
  
  <p>ID for model is provided from service so I cleaned up the duplicate instances of one entity (same ID).</p>
  
  <pre><code>var clientList = service.GetAllClients(); // return IEnumerable&lt;Client&gt; // return 10K clients
  var filteredList = Client.RemoveDuplicateInstancesSameEntity(clientList); // return IEnumerable&lt;Client&gt;
  
  int cur = 0;
  in batch = 100;
  
  while (true)
  {
  logger.Trace("POINT A : get next batch");
  var importSegment = filteredList.Skip(cur).Take(batch).OrderBy(x=&gt; x.Id);
  if (!importSegment.Any())
     Break;
  
  logger.Trace("POINT B: Saving to DB");
  importSegment.ForEach(c =&gt; repository.addClient(c));
  logger.Trace("POINT C: calling persist");
  repository.persist();
  cur = cur + batch;
  }
  </code></pre>
  
  <p>logic is simple, breaking it up into batch to speed up the process.  each 100 Client create about 1000 insert statement (for child records and 1 many to many table).</p>
  
  <p>using profiler and logging to analyze this.  right after it insert </p>
  
  <p>log show POINT B as the last step all the time.  but i dont see any insert statement yet in profiler.  then 2 minutes later, I see all the insert statement and then the POINT B for the next batch. and 2 minutes again.</p>
  
  <p>did I do anything wrong or is there is setting or anything I can do to improve?</p>
  
  <p>insert 1k records seems to be fast.  Database is wiped out when process start so no records in there.  doesn't seem to be an issue with SQL slowness but EF generating insert statement?</p>
  
  <p>although the project works but it is slow.  I want to speed it up and understand more about EF when it comes to big chunks of data.  or is this normal?</p>
  
  <p>the first 100 is fast and then is getting slower and slower and slower.  seems like issue at POINT B.  is it issue with too much data repo/dbcontext can't handle it in timely manner?  </p>
  
  <p>repo is inheritance from dbcoontext and addClient is simply</p>
  
  <pre><code>dbcontext.Client.Add(client)
  </code></pre>
  
  <p>Thank you very much.</p>