title: Collection was modified; enumeration operation may not execute , even when i create a copy of the current object
body: <p>I have the following repository method :-</p>
  
  <pre><code>public void DeleteVM(int id, string username)
          {
              var VM = tms.TMSVirtualMachines.SingleOrDefault(a =&gt; a.TMSVirtualMachineID == id);
              var auditinfo = IntiateTechnologyAudit(tms.AuditActions.SingleOrDefault(a =&gt; a.Name.ToUpper() == "DELETE").ID,
                      VM.Technology.TechnologyType.AssetTypeID,
                   username, VM.TMSVirtualMachineID);
              var technology = tms.Technologies.SingleOrDefault(a =&gt; a.TechnologyID == id);
              technology.IsDeleted = true;
              tms.Entry(technology).State = EntityState.Modified;
              var vm2 = VM;
              foreach(var ip in vm2.Technology.TechnologyIPs)
              {
              tms.TechnologyIPs.Remove(ip);
  
              }
              tms.TMSVirtualMachines.Remove(VM);
                        InsertOrUpdateTechnologyAudit(auditinfo);
          }
  </code></pre>
  
  <p>But i am getting the following exception :-</p>
  
  <blockquote>
    <p>System.InvalidOperationException was caught   HResult=-2146233079<br>
    Message=Collection was modified; enumeration operation may not
    execute.   Source=System.Core   StackTrace:
           at System.Collections.Generic.HashSet`1.Enumerator.MoveNext()</p>
  </blockquote>
  
  <p>although i have created a copy of the VM and i perform the foreach over it..</p>