locked
EF4.0 problem when trying to populate a new entity's EntityCollection<> with existing entities RRS feed

  • Question

  • I'm having some problems mapping data from a DTO to a new entity.  My new entity has an EntityCollection<> property which is supposed to be filled by existing entities.  When I try adding them, I get an exception stating: "The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects." 

    I understand that this is expected behavior, since my new entity is not attached to any context when I try the mapping, and EF considers a null context to be a separate context.  I just don't know how to remedy the problem.

    Thursday, June 2, 2011 4:40 PM

Answers

All replies