I am trying to attach and add disconnected entities to an Entity Framework context. For example:
I have a Customer entity and a navigation property to detail Order entity. The idea is to get the Customer entity and make modifications to the entity and then also add new Order entities to the Customer entity.
The problem starts when I try to Attach (I assume this is the correct method to use.) the Customer entity. Because the whole object graph is now being attached I get the following error:
"An object with a temporary EntityKey value cannot be attached to an object context."
I understand that the error is because of the added Order entities that should be Added and not Attached.
Is there a way to Attach or Add a existing entity with new child entities to a context?