I have a parent table and child table, where the parent has a one-to-many relationship with the children.
I want to delete some of the children and I want the parent's child collection to reflect that change.
If I delete the selected children using
RemoveRange, then the child collection doesn't get updated. If I use
Remove to remove the children from the child collection then (apparently) it's not as efficient as using
So I have to use
RemoveRange to delete the children efficiently and then use
Remove to remove them from the child collection. Is this correct or is there a better way of doing it?
RemoveRange, where you will save time is in the overhead around removing the objects from the child collection, especially around change tracking which will run once rather than once for each object with
Either way, you will only make one trip to the database when you call
So, in your example,
RemoveRange is redundant and can be omitted.