I am new to Entity Framework and want to know how to modify the connection string in code.
Here is my code
using (var context = new PushjobModel.PushjobEntities())
{
var list = context.GetAllActivePushjobs();
foreach (PushjobModel.Pushjob item in list)
{
item.IsActive = false;
item.IsSent = true;
}
context.SaveChanges();
}
I have a configuration file in my ASP.NET webforms application which contains a list of connection strings for 100+ databases. Before I call context.GetAllActivePushjobs(); I want to change the connection string.
With old ADO.NET I have been using following approach for long time and it works perfectly
spPremisesReadTableAdapter taPremises = new spPremisesReadTableAdapter();
taPremises.Connection.ConnectionString = GetConnectionString(CompanyName);
taPremises.GetData();
...
public static void GetConnectionString(string CompanyName)
{
string connectionstring = System.Web.Configuration.WebConfigurationManager.ConnectionStrings[CompanyName].ConnectionString;
}
Can anyone help?