parallel.foreach and insertonsubmit primarykey issue
<p>I'm trying to implement <code>a parallel.foreach</code> that inside of it has an <code>InsertOnSubmit</code></p>

<p>Most of the time everything works fine, but every so often I get an exception:</p>

<blockquote>
  <p>Violation of PRIMARY KEY constraint - Cannot insert duplicate key </p>
</blockquote>

<p>I've tried it with different parallelOptions and it isn't consistant.  I am not using the same DataContext for each iteration of the loop, is there any suggestions for using <code>InsertOnSubmit</code> from within a <code>parallel.foreach</code> loop?</p>

<pre><code>while (myConcurrentDictionary.Count &gt; 0)
{
    Parallel.ForEach(myConcurrentDictionary, pOptions, (KVP, loopState) =&gt;
    {
        pOptions.CancellationToken.ThrowIfCancellationRequested();

        passCount++;
        MsgLog.WriteLine(KVP.Key);
        processKVP(KVP.Key, KVP.Value, loopState);
    }); //End of Parallel.ForEach loop
}


processKVP()
{
    ...
    DCtxt myDC = new DCtxt();

    myDC.TABLE.InsertOnSubmit(new TABLE
    {
       ...
    });
    insertCount++;

    if ((insertCount % 100) == 0)
    {
      myDC.SubmitChanges();
    }
}
</code></pre>
