I'm using EF4 and I'm running into a problem when I try to do something that looks quite trivial to me.
I have two entities, let's call them A and B. These entities have a many-to-many association between them with a navigation property on A that contains a list of related B entities.
What I want to do is to add existing B entities to a new A entity. When I try to do that, I get an exception:
AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges.
Has anyone run into such a problem?
More info that might be relevant:
- I've created the DB from the model.
- I have a base entity that both A and B entities inherit from.
Update: Found a solution - detach the linked entity and re-attach it to the context, then everything goes as planned.