title: How do I test whether a DbContext is in memory?
body: <p>I use <code>.Net Core 2.1.</code> My application uses <code>Entity Framework Core</code>, with a context <code>CoreDbContext</code> that derives from <code>DbContext</code>.</p>
  
  <p>For unit testing, I use an in memory version of <code>CoreDbContext</code>, resulting in this code in my <code>Startup.cs</code>:</p>
  
  <pre><code>if (useInMemoryDatabase)
  {
      services.AddDbContext&lt;CoreDbContext&gt;(options =&gt; 
             options.UseInMemoryDatabase("dbname"));
  }
  else
  {
      services
        .AddDbContext&lt;CoreDbContext&gt;(options =&gt; 
             options.UseSqlServer(DefaultDbConnectionString));
  }
  </code></pre>
  
  <p>I also have methods that access the database via the context. These sometimes need to know whether the context is in memory or not, because an in memory context behaves differently from a normal one:</p>
  
  <pre><code>void AddRecordX(CoreDbContext context)
  {
      bool contextIsInMemory = .....;
  
  }
  </code></pre>
  
  <p>How can I test whether a context is in memory or associated with a real <code>SQL Server database</code>?</p>