title: Parallel.ForEach() missing list items
body: <p>In my tests without using <code>Parallel.ForEach()</code>, 3500 records are processed.  </p>
  
  <p>But with Parellel a random lower number of records are processed each attempt.  (3402, 3375, 3471, etc).  I figured out that DBSet didn't support parellel programming, so I am moving my items into a list, then dealing with the list later. (not ideal)  Some of the records that are missed, are added to the List as null objects. </p>
  
  <p>What am I missing?</p>
  
  <pre><code>       public int Execute(CalculateAutoClassRatesCommandRequest request)
          {
              int recordCount = 0;
              var autoClassCalculations = new List&lt;AutoClassCalculation&gt;();
              var options = new ParallelOptions { MaxDegreeOfParallelism = 2 };
              Parallel.ForEach(request.BaseCalculations, options, baseCalculation =&gt;
                  {
                      foreach (var autoClass in request.AutoClasses
                          .Where(autoClass =&gt; baseCalculation.BaseClassId == autoClass.BaseClassId)
                          .Where(autoClass =&gt; autoClass.AutoClassForms != null))
                      {
                          foreach (var form in autoClass.AutoClassForms)
                          {
                              recordCount++;
                              var calcRate = CreateAutoClassCalculation(autoClass.AutoClassRoundingRules, form, baseCalculation); 
  autoClassCalculations.Add(calcRate);
                          }
                      }
                  });
  
              foreach (var autoClassCalculation in autoClassCalculations)
              {
                  request.AutoClassCalculationsDbSet.Add(autoClassCalculation);
              }
              request.ratingContext.SaveChangesWithChangeTracking(request.Identity);
  
              return recordCount;
          }
  
  private static AutoClassCalculation CreateAutoClassCalculation(
      IEnumerable&lt;AutoClassRoundingRule&gt; autoClassRoundingRules, 
      AutoClassForm autoClassForm,
      BaseCalculation baseCalculation)
  {
      var autoClassCalculation = new AutoClassCalculation()
      {   
          BaseCalculation = baseCalculation, 
          AutoClassForm = autoClassForm, 
          BaseCalculationId = baseCalculation.BaseCalculationId, 
          AutoClassFormId = autoClassForm.AutoClassFormId
      };
  
      var roundingRule = autoClassRoundingRules != null ? autoClassRoundingRules.FindMatchingAutoClassRoundingRule(autoClassForm.AutoClassId, autoClassCalculation.CalcRate) : new AutoClassRoundingRule();
      autoClassCalculation.CalculateRate(roundingRule);
  
      return autoClassCalculation;
  }
  </code></pre>