I've created a repository class and have the following code:
public class InventoryDA : Accident_Reporting_Entities
{
}
Web.config:
<add name="Accident_Reporting_Entities" connectionString="metadata=res://*/Models.IncidentModel.csdl|res://*/Models.IncidentModel.ssdl|res://*/Models.IncidentModel.msl;provider=System.Data.SqlClient;provider connection string="data source=server;initial catalog=Accident_Reporting;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="Accident_Reporting_Entities2" connectionString="metadata=res://*/Models.IncidentModel.csdl|res://*/Models.IncidentModel.ssdl|res://*/Models.IncidentModel.msl;provider=System.Data.SqlClient;provider connection string="data source=server;initial catalog=Accident_Reporting2;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
I'm wondering how I can have multiple connections and replace Accident_Reporting__Entities with another connection string. The connections are of different databases that have the same design. Is it possible to check for a session variable and change this connection according to the variable, and would this be the best way?
Accident_Reporting_Entities, so answers you can get may vary a lot. Anyway you can implement two "different" DbContext types which you setup using two different connection strings. And then your logic will decide which context to use. Will it be http session, http request, user input or something else, it's of course up to you :)