title: isn't SaveChanges() managed by transactions?
body: <p>I've several &quot;thread&quot; (i.e. Hangfire task) that will run in parallel this kind of function (each call passing different <code>systemId</code>):</p>
  <pre><code>private void UpdatePartners(int systemId)
  {
      try
      {
          using (var ctx = new MyEntities())
          {
              var partners = ctx.PartnersUpdate.Select(s =&gt; s)
                .Where(w =&gt; w.SystemId.Equals(systemId) &amp;&amp; statusToEvaluate.Contains(w.Status)).OrderByDescending(p =&gt; p.UpdateAt).Take(500);
  
              var partnersId = partners.Select(p =&gt; p.PartnerId).ToList();
  
              var partnersToUpdate = ctx.vPartnersSystems.AsNoTracking().Select(s =&gt; s)
                      .Where(w =&gt; w.SystemId.Equals(systemId) &amp;&amp; partnersId.Contains(w.Id) &amp;&amp; w.Validity.Equals(true))
                      .ToList();
  
              foreach (var partner in partners)
              {
                  // some operations on &quot;partner&quot;, using data from &quot;partnersToUpdate&quot;
                  
                  ctx.PartnersUpdate.AddOrUpdate(partner);
              }
  
              ctx.SaveChanges();
          }
      }
      catch (Exception ex)
      {
          Logger(ex, &quot;Error on UpdatePartners&quot;);
      }
  }
  </code></pre>
  <p>Unfortunately, sometimes I get this error:</p>
  <pre><code>UpdatePartners(Int32 systemId) in C:\myProjects\XYZ\Controllers\TestController.cs:line 16 Void HandleReaderException(System.Exception)
  System.Data.SqlClient.SqlException (0x80131904): Transaction (Process ID 130) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
  </code></pre>
  <p>It seems when iterate the partners (but I could be wrong):</p>
  <pre><code>foreach (var partner in partners)
  </code></pre>
  <p>why this? If <code>UpdatePartners()</code> is called in parallel with different <code>systemId</code> (which means that the query will catch every time <em>different records</em>), why it handle &quot;deadlocks&quot;?</p>
  <p>Aren't deadlocks for the &quot;same rows&quot; read/updated?</p>