title: Using the entity framework to add existing entities to a collection on a newly created entity
body: <p>I am using the Entity framework to create a new order.  The order contains a collection of contacts, a many to many relationship.  I want to add a reference to an existing contact on the order on creation of the order.  Both Order and Contact a Entity Objects.</p>
  
  <pre><code> Order order = new Order();
  
   //set details on order
  
   Contact contact = new Contact();
  
   EntityKey contactKey =
                      new EntityKey("OrderDetails.Contact",
                          "contact_id", contact.Key.Id);
  
   contact.EntityKey = contactKey;
   contact.contact_id = contact.Key.Id;
  
   order.Contact.Attach(contact);  // throws an exception!
  
   OrderDetails ordTable = new OrderDetails();
              ordTable.AddToOrder(order);
              int result = orgTable.SaveChanges();
  </code></pre>
  
  <p>When I go to attach, this exception is thrown:</p>
  
  <p>"Attach is not a valid operation when the source object associated with this related end is in an added, deleted, or detached state. Objects loaded using the NoTracking merge option are always detached."</p>
  
  <p>I know I'm probably missing a step or not fully understanding how the entity framework handles many-to-many relationships.</p>