title: EF attaching object to context in foreach working only first time
body: <p>I have a list of objects that I need to attach to the Context in order to track changes and, afterward, saving them, but the foreach iterating the items executes only the first time, after that the method ends.
  I'm certain that those items already exist in the database.</p>
  
  <p>I have tried both calling the <code>.Attach()</code> method and setting the Entry state to Unchanged.</p>
  
  <pre class="lang-cs prettyprint-override"><code>
  protected override Task SetViewModelPropertiesAsync()
          {
  
              SelectedItems.ForEach(l =&gt;
              {
                  //Context.Pap_Pedido_ODP.Attach(l);
                  Context.Entry(l).State = System.Data.Entity.EntityState.Unchanged;
                  // After the first iteration the method ends
              });
  
  
              return base.SetViewModelPropertiesAsync();
          }
  </code></pre>
  
  <p>I expect all the items to be added to context but after the first iteration of the foreach loop breaks the method and continues to the next one, without even giving an exception.</p>
  
  <p>EDIT:
  There is more code after the foreach that is being skipped when I do either the Attach or EntityState.
  If I comment both the code executes correctly</p>