title: ASP.NET Core OnModelCreating force to fire in every request
body: <p>ASP.NET Core OnModelCreating force to fire in every request</p>
  
  <p>I have ASP.NET Core (1.1.0) and SQL Server database. In login page I have a form with a select box with name of companies.</p>
  
  <p>For example:</p>
  
  <ul>
  <li>Company 1  </li>
  <li>Company 2</li>
  </ul>
  
  <p>If a user selects the the first "Company 1", I need to rename all the tables with a company prefix:</p>
  
  <pre><code>protected override void OnModelCreating(ModelBuilder builder)
  {
      base.OnModelCreating(builder);
  
      foreach (var entity in builder.Model.GetEntityTypes())
      {
         entity.Relational().TableName = "Company 1" + entity.DisplayName();
      }
  }
  </code></pre>
  
  <p>It's working perfectly fine, but the problems is when user selects the wrong company, or logs out of the system and logs back in with a different company, OnModelCreating never gets called again and I can't reconfigure the dbContext.</p>
  
  <p>Is it possible to force OnModelCreating for every request?</p>
  
  <p>Or change table name after dbContext initilization?</p>
  
  <p>Thanks!</p>