I have the following repository method :-
public void DeleteVM(int id, string username)
{
var VM = tms.TMSVirtualMachines.SingleOrDefault(a => a.TMSVirtualMachineID == id);
var auditinfo = IntiateTechnologyAudit(tms.AuditActions.SingleOrDefault(a => a.Name.ToUpper() == "DELETE").ID,
VM.Technology.TechnologyType.AssetTypeID,
username, VM.TMSVirtualMachineID);
var technology = tms.Technologies.SingleOrDefault(a => 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);
}
But i am getting the following exception :-
System.InvalidOperationException was caught HResult=-2146233079
Message=Collection was modified; enumeration operation may not execute. Source=System.Core StackTrace: at System.Collections.Generic.HashSet`1.Enumerator.MoveNext()
although i have created a copy of the VM and i perform the foreach over it..