Why does looping through a parent collection removing children cause .net to throw a invalid operation exception for modifying the collection? This exception should only throw if the collection being iterated over changes, not it's members.
Example:
EntityCollection<ParentEntity> parents = GetParents();
foreach (ParentEntity parent in parents)
{
parent.Children.RemoveRange(parent.Children.Where(x=> !x.IsActive));
}
In the example we are not changing the number of items in the parents collection. If I spin up this example with POCOs I do not get the exception. Why does this exception get thrown?