title: Determine if the context of an entity proxy has been disposed
body: <p>In a EF 6 project, I am writing validation functions for entities. some are static while others are instance methods of the entities themselves.</p>
  
  <p>Ignoring whether this is bad practice or not, I'd like to check whether the entities were created using a context and if so, whether they are still attached.</p>
  
  <p>Please note that these functions do NOT have access to the context object, just the entity classes.</p>
  
  <p>As an example, a method validates <code>Department</code> entity and cascades validation to all associated <code>Department.Employee</code> instances.</p>
  
  <ul>
  <li>If the hierarchy was created manually, validation will succeed.</li>
  <li>If the hierarchy was created using a context which is still alive, validation will succeed albeit slower.</li>
  <li>If the hierarchy was created using a context which has been disposed, validation will fail with an <code>ObjectDisposedException</code> (provided proxy-creation was enabled and <code>.Include(***)</code> was not used).</li>
  </ul>
  
  <p>So the question, is it possible to detect the above scenarios without access to a <code>DbContext</code> instance? If not, how can we best validate entire hierarchies irrespective of how they were created.</p>
  
  <pre><code>var result = true;
  var departments = ???; // Constructed manually or through a DbContext instance.
  
  foreach (var department in departments)
  {
      result &amp;= department.Validate();
  
      foreach (var employee in department.Employees)
      {
          result &amp;= employee.Validate();
      }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> Please note that this is for a desktop application that cannot have long-running <code>DbContext</code> instances. they are almost always disposed immediately after retrieving data. Re-querying the database does not seem a viable option for validation since it is triggered by trivial user input and would slow down the entire user experience.</p>