title: Detaching object from context in entity
body: <p>I'm currently using Entity Framework and am running into this issue:</p>
  
  <p>The relationship between the two objects cannot be defined because they are attached to different <code>ObjectContext</code> objects.</p>
  
  <p>For the page load sequence, I am filling <code>dropdownlists</code> via this:</p>
  
  <pre><code>using (DatabaseEntities db = new DatabaseEntities())
          {
              MyDictionary = new Dictionary&lt;Guid, Person&gt;();
              var List= from emp in db.Set select emp;
              ...
  
              foreach (Employee emp in List)
              {
                  MyDictionary.Add(emp.id, emp);
  </code></pre>
  
  <p>The other function is a 'Next' button to close this page and open another one.  </p>
  
  <pre><code>private void StoreInfo()
      {
          Person theLead= MyDictionary[new Guid(this.Lead.SelectedValue)]; 
          ....
          this.Selected.Lead= theLead;
  </code></pre>
  
  <p>I am storing a dictionary in the Session state here</p>
  
  <pre><code>public Dictionary&lt;Guid,Person&gt; MyDictionary
      {
          get
          {
              return Session["MyDictionary"] as Dictionary&lt;Guid,Person&gt;;
          }
          set
          {
              Session["MyDictionary"] = value;
          }
      }
  </code></pre>
  
  <p>How do I go about detaching each person from the first context so I can continue with the validation in the page?  I have tried </p>
  
  <pre><code>db.Detach(emp) 
  </code></pre>
  
  <p>before the </p>
  
  <pre><code>MyDictionary.Add(emp.id, emp);
  </code></pre>
  
  <p>but it didn't work.  </p>