title: EF Hold an entity out of Context and get back when needed
body: <p>I have a Sales Receipt Form which uses EF4.3 ObjectContext. I am struggling to figure out to hold an receipt (an entity in EF ObjectContext) and move out of context and to retrieve back when the user wants it back. The situation is whenever the sales receipt form is closed, the context goes away. And the issue is the user should be able to retrieve it back and add to the current context. </p>
  
  <p>The code to detach</p>
  
  <pre><code>Serialize(receipt, savepath)
  While Receipt.RECEIPTLINEs.Count &gt; 0
        Context.Detach(Receipt.RECEIPTLINEs.First)
  End While
  Context.Detach(Receipt)
  AddNewReceipt()
  </code></pre>
  
  <p>The code to Attach</p>
  
  <pre><code>Dim receipt = DeSerialize(savepath)
  Context.Attach(receipt)
  </code></pre>