title: How to handle long-running operations with the Entity Framework?
body: <p>Our team is developing a machine that will perform a physical process on a tray that holds vials of medical samples.  The physical process will take approximately 1.5 hours.  The tray and related vials are entities, loaded from a database using the Entity Framework.  As the process runs, the device will update values on the entities.  The changes may happen minutes or seconds apart.  At the end of certain steps, between 10 and 45 minutes apart, we want to save those entities back to the database, and keep going.</p>
  
  <p>Is it acceptable to have an Entity Framework context open for 1.5 hours?  Can I make changes and save the entities multiple times during that time period using that context?  If not, what is the best way to handle this?  </p>
  
  <p>Some ideas so far:</p>
  
  <ul>
  <li>We could use the attach/detach capability.  This should allow us to make changes to the entities outside of the context, then create a new context and attach the entity when we want to save, then detach it to continue working.</li>
  <li>We could create a new context every time we want to change one of the entities.  But I don't think we want to save every time we make a change.</li>
  <li>We could copy the entities to business objects, and make the changes there.  Then when we want to save, we would open a context and copy the changes into the entities, and save.</li>
  </ul>