title: Entity Framework and impersonation
body: <p>I'm incorporating Entity Framework and ASP.NET Dynamic Data into an existing application that is setup to use impersonation="true" in the web.config, however the previous developers chose an approach where they revert back to the app pool identity for each DAL call they made</p>
  
  <pre><code>private WindowsImpersonationContext context = null;
  
  public void RevertToAppPool()
  {
      if (!WindowsIdentity.GetCurrent().IsSystem)
      {
          context = WindowsIdentity.Impersonate(System.IntPtr.Zero);
      }
  }
  
  public void UndoImpersonation()
  {
      if (context != null)
      {
          context.Undo();
      }
  }
  </code></pre>
  
  <p>I've been asked to preserve this behavior while using Entity Framework ...given that the entity objects are used all over the place (in LINQ to EF queries, manual calls, behind-the-scenes calls by the framework etc.), where would be the appropriate places in the partial classes to make the appropriate calls to RevertToAppPool and UndoImpersonation for every call?</p>