title: Best Approach to link MVC Application with multiple database and switch databases?
body: <p>I am working on a new project and client asked me to create separate SQL databases for their three different branches. The main problem is to switch the connection and creating the relationship between them in the Asp.Net MVC project.
  I will be using Entity Framework Code First Approach to develop the application. I am thinking to create three different connections in the Web.Config file of the application.</p>
  
  <h2>SQL Connections</h2>
  
  <pre><code>&lt;add name="Con1" connectionString="Data Source=.\SqlExpress;Initial Catalog=dbBranch1;
       Integrated Security=True" providerName="System.Data.SqlClient" /&gt;
  
  &lt;add name="Con2" connectionString="Data Source=.\SqlExpress;Initial Catalog=dbBranch2;
       Integrated Security=True" providerName="System.Data.SqlClient" /&gt;
  
  &lt;add name="Con3" connectionString="Data Source=.\SqlExpress;Initial Catalog=dbBranch3;
       Integrated Security=True" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>Now the problems is I don't know how to switch the connections based upon the branch user selects from the drop-down list. If user selects the <strong><em>Branch1</em></strong> in the drop-down list while inserting the record then the record should be inserted into <strong><em>Branch1 Database</em></strong>. How will I configure three connections in Application Db Context File? </p>
  
  <h2>Application Db Context</h2>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext()
          : base("Con1", throwIfV1Schema: false)
      {
      }
  
      public static ApplicationDbContext Create()
      {
          return new ApplicationDbContext();
      }
  }
  </code></pre>
  
  <p>Likewise, joining the three databases records and getting result will also be the headache. I might need to write stored procedure during seeding to get records.</p>
  
  <p>I offered my client to create one database and have a table of branches and do normalization. But he wants three separate databases. What is the best architecture or approach to achieve this? </p>