I have the two entities, Arena and Regulator, which have a many to many relationship between them. I have implemented what seems to be the EF code first accepted solution (
The problem here is not that EF doesn't update relationships, it's that it doesn't automatically do so.
What you need to do is retrieve the current Arenas for the Regulator, then walk the list and delete any entries that exist that are not in your new list. Then you need to add any entries that do not already exist. Then SaveChanges.
This does work, but your problem is that you're trying to either blindly add relationships that may already exist, or trying to update ones that don't. You have to actually get the existing list and figure out which relationships to either add or delete.
I understand you've already found a solution that works for you, my point here is just that if you're trying to do a strict EF based solution, then you were going at it the wrong way.
I suppose another option would be to delete all the relationships, SaveChanges, then add the new set and SaveChanges again. This would delete some that already exist if there is overlap, but would be fairly straight forward and simple.
Another option is to Delete the existing, re-add them, then walk the original set and change the state of any that previously existed to Modified or None. A little more involved, but would only require on save.