title: Entity Framework - Effect of MultipleActiveResultSets on Caching
body: <p>So I have a Class that looks something like the following. There is a thread that does some work using an Entity Framework Code First DbContext. </p>
  
  <p>The problem I'm having is that it seems like m_DB context is caching data even though it should be disposed and recreated for every processing loop.</p>
  
  <p>What I've seen is that some data in a relationship isn't present in the models loaded. If I kill and restart the process suddenly the data is found just like it should.</p>
  
  <p>The only thing I can think of is this app is using the MultipleActiveResultSets=true in the database connection string, but I can't find anything stating clearly that this would cause the behavior I'm seeing.</p>
  
  <p>Any insight would be appreciated.</p>
  
  <pre><code>
  public class ProcessingService
  {
  
    private MyContext m_DB = null
    private bool m_Run = true;
  
    private void ThreadLoop()
    {
      while(m_Run)
      {
        try
        {
          if(m_DB == null)
            m_DB = new MyContext();
        }
        catch(Exception ex)
        {
          //Log Error
        }
        finally
        {
          if(m_DB != null)
          {
            m_DB.Dispose();
            m_DB = null;
          }
        }
      }
    }
  
    private void ProcessingStepOne()
    {
      // Do some work with m_DB
    }
  
    private void ProcessingStepTwo()
    {
      // Do some work with m_DB
    }
  }
  
  </code></pre>