title: EF7 Multiple datacontext
body: <p>I've got an Asp.Net 5 web application which use EF7 and SQL Server 2014. Now I need to make second DBContext which will connect to SQL Server 2008 R2. For some reason I'm able to connect but not able to get any data from database.</p>
  
  <p>config.json:</p>
  
  <pre><code>"Data": {
  "PMSConnectionString": "Data Source=xxxx;User ID=xxxx;Password=xxxx;Initial Catalog=xxxx;",
  "MTOCL2ConnectionString": "Server=xxxx;Database=xxxx;User Id=xxxx;Password=xxxx;"
  } 
  </code></pre>
  
  <p>Startup.cs:</p>
  
  <pre><code>public Startup(IHostingEnvironment env)
      {
          // Setup configuration sources.
          var configurationBuilder = new ConfigurationBuilder()
              .AddJsonFile("config.json")
              .AddEnvironmentVariables();
       Configuration = configurationBuilder.Build();
      }
  
  
  
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddMvc().AddJsonOptions(options =&gt;
          {
              options.SerializerSettings.ContractResolver =
                  new CamelCasePropertyNamesContractResolver();
              options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
          });
  
          services.AddCaching(); // Adds a default in-memory implementation of IDistributedCache
          services.AddSession(s =&gt; s.IdleTimeout = TimeSpan.FromMinutes(360));
  
          services.AddEntityFramework()
              .AddSqlServer()
              .AddDbContext&lt;MTOCL2Context&gt;(options =&gt;
                  options.UseSqlServer(Configuration["Data:MTOCL2ConnectionString"])
                  ).AddDbContext&lt;PMSContext&gt;(options =&gt;
                  options.UseSqlServer(Configuration["Data:PMSConnectionString"]))
  
              ;
  
      }
  
      public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
      {
          loggerFactory.MinimumLevel = LogLevel.Information;
          loggerFactory.AddConsole();
          loggerFactory.AddDebug();
  
          app.Use(async (context, next) =&gt;
          {
              context.Response.Headers.Append("Cache-Control", "private, no-store");
              await next();
          });
  
          app.UseSession();
  
          app.UseIISPlatformHandler();
  
          app.UseStaticFiles();
  
          app.UseMvc();
      }
  </code></pre>
  
  <p>MTOCL2Context.cs:</p>
  
  <pre><code>public class MTOCL2Context:DbContext
  {
      public DbSet&lt;SubLotPriority&gt; SubLotPriorities { get; set; }
  }
  </code></pre>
  
  <p>UserController:</p>
  
  <pre><code>[Route("api/[controller]")]
  public class UsersController : Controller
  {
      private readonly PMSContext _dbContext;
      private readonly MTOCL2Context _dbContext2;
  
      public UsersController(MTOCL2Context dbContext2, PMSContext dbContext)
      {
          _dbContext2 = dbContext2;
          _dbContext = dbContext;
      }
  }
  </code></pre>
  
  <p>When I run application and try to get data from SubLotPriority, I get error:</p>
  
  <blockquote>
    <p>Evaluation of method System.Linq.SystemCore_EnumerableDebugView'1[[SublotPriority...</p>
  </blockquote>
  
  <p>I actually don't get any error, when I go into dbcontext I don't get any results and error message appear on the screen. Don't know how to get full message:
  <a href="https://i.stack.imgur.com/SnuK1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SnuK1.png" alt="Error Message"></a>   </p>