title: How to dynamically pass connectionstrings in EF5
body: <p>I'm struggling with a project, converted to .net 4.5.</p>
  
  <p>I have some functions like this:</p>
  
  <pre><code>Public Shared Function Load(iJaar As Integer, iKwartaal As Integer) As List(Of LoonDetail_121)
      Dim oLoonDetails As New List(Of LoonDetail_121)
      Try
           Dim oDB As New SDWMasterSDWDBEntities(DBConnections.ConnStringPrisma)
           Dim dStartDate As New Date(iJaar, ((iKwartaal - 1) * 3) + 1, 1)
           Dim dEndDate As New Date(iJaar, ((iKwartaal - 1) * 3) + 4, 1)
  
           oLoonDetails = oDB.LoonDetail_121.Where(Function(x) x.EindPeriode_121 &gt;= dStartDate And
                                                x.EindPeriode_121 &lt; dEndDate).ToList
       Catch ex As Exception
           Throw New Exception(GetCurrentMethod.Name &amp; " " &amp; ex.Message)
       End Try
       Return oLoonDetails
   End Function
  </code></pre>
  
  <p>When I convert this function to EF5, I get errors, since my SDCDBLonenEntities is not inherited anymore from ObjectContext, but it is inherited from DbContext.<br/>
  Before, EF automatically created a constructor where I can pass my Connection String.
  This is very easy, because I use different connectionstrings, depending on my Solution Configuration (Debug/Release).<br/>
  In EF5, the constructor doesn't accept Connectionstrings anymore.
  I tried to create a partial class of my Entity, and create my own constructor, but I can't get this working:</p>
  
  <pre><code>Partial Public Class SDWMasterSDWDBEntities
      Inherits DbContext
  
      Public Sub New(sConnString As String)
          MyBase.New(sConnString)
      End Sub
  End Class
  </code></pre>
  
  <p>For another project, I adapted my Project-file to use different app.config files for each solution configuration, but that was a p.i.t.a to maintain and for me not a clean solution.</p>
  
  <p>So my question is: How can I use EF5 with my own personal Connectionstrings?</p>
  
  <p>These are my Connection Strings by the way:</p>
  
  <pre>
  #If DEBUG Then
      Friend ConnStringSDW As String = "metadata=res://*/Entities.SDWDB.csdl|res://*/Entities.SDWDB.ssdl|res://*/Entities.SDWDB.msl;provider=System.Data.SqlClient;provider connection string='data source=SDWDB01\SDWSQL;initial catalog=SDWDB_DEV;persist security info=True;user id=usr;password=pwd;multipleactiveresultsets=True;App=EntityFramework'"
  #Else
      Friend ConnStringSDW As String = "metadata=res://*/Entities.SDWDB.csdl|res://*/Entities.SDWDB.ssdl|res://*/Entities.SDWDB.msl;provider=System.Data.SqlClient;provider connection string='data source=SDWDB01\SDWSQL;initial catalog=SDWDB_PROD;persist security info=True;user id=usr;password=pwd;multipleactiveresultsets=True;App=EntityFramework'"
  #End If
  </pre>
  
  <p>And I get the error "The entity type SDW_USERS_MASTER is not part of the model for the current context.", when I execute this function:</p>
  
  <pre><code>Public Shared Function LoadAll() As List(Of SDW_USERS_MASTER)
      Dim oUsers As New List(Of SDW_USERS_MASTER)
      Try
          Using oDB As New SDWMaster.SDWMasterSDWDBEntities(DBConnections.ConnStringSDW)
              oUsers = (From tmpUsers In oDB.SDW_USERS_MASTER
                           Select tmpUsers).ToList.OrderBy(Function(x) x.Login).ToList
          End Using
      Catch ex As Exception
          Debug.Print(ex.Message)
          Throw New Exception(GetCurrentMethod.Name &amp; " " &amp; ex.Message)
      End Try
      Return oUsers
  End Function
  </code></pre>