How to: Change Relationships Between POCO Entities
When the creation of proxy objects is disabled or when a POCO entity is created without its proxy object, you must call the DetectChanges method on the ObjectContext to synchronize the changes with the ObjectStateManager. In addition to detecting changes in scalar properties, this method detects changes in relationships, including adding, deleting, or changing a related object. For more information, see Tracking Changes in POCO Entities. The SaveChanges method calls DetectChanges, so you do not have to call DetectChanges explicitly if you do not need immediate synchronization of the relationships.
The example in this topic uses the POCO custom data classes that are defined in How to: Define POCO Entities and an AdventureWorks-based data model that is defined in How to: Customize Modeling and Mapping Files to Work with Custom Objects.
This example changes the current contact for an order to a different contact. The DetectChanges method is called by the SaveChanges method before changes are saved to the data source.