document.write('
  1. public void AddALotOfEntities(IEnumerable<Entity> entitiesToAdd)
  2. {
  3.     var batchSize = 100;
  4.     var batches = entitiesToAdd.Batch(batchSize); // point 2
  5.  
  6.     Parallel.ForEach(
  7.         batches,
  8.         new ParallelOptions { MaxDegreeOfParallelism = 4 }, // point 5
  9.         batch =>
  10.         {
  11.             using (var context = new MyDbContext("")) // point 3
  12.             {
  13.                 context.Configuration.AutoDetectChangesEnabled = false; // point 1
  14.                 context.Configuration.ValidateOnSaveEnabled = false; // point 6
  15.                 context.DbSetWithEntities.AddRange(batch); // point 4
  16.                 context.SaveChanges();
  17.             }
  18.         });
  19. }
');