Adding existing entity to navigation property of a different entity

Posted by Shay Friedman on Stack Overflow See other posts from Stack Overflow or by Shay Friedman
Published on 2010-05-09T14:38:57Z Indexed on 2010/05/09 14:48 UTC
Read the original article Hit count: 466

Filed under:

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?

© Stack Overflow or respective owner

Related posts about entity-framework