Multiple database link

I have 2 windows Azure Database serveur with same tables scheme on them but with differents data. In my site I connect with my first db like this: Web.config

<add name="FirstDBContext" connectionString="..." providerName="..." />


public class FirstDBContext: DbContext
   public DbSet<Data> Datas{ get; set; }


private UsersContext db = new UsersContext();
public ViewResult Index()
   return View(db.Datas.ToList());

As you can see I have my db set in the code. How can I change this to be able to change dynamically to one DB to another with a drop list for example ?

Thanks a lot !


You can pass the name of the connection string when initializing the UsersContext

For example if you have the following connection stirngs

<add name="csFirstDB" connectionString="..." providerName="..." />
<add name="csSecondDB" connectionString="..." providerName="..." />

You can change your UsersContext to

public class UsersContext : DbContext {
    public UsersContext (string connectionName) : base(connectionName){ }

Now when you initialize the UsersContext class object, pass in the connection string name and it will refer to that particular db.

Need Your Help

using GroupBy to get Employee Name, EmployeeID, sum by Pay by category using LINQ

c# .net linq group-by

List&lt;ps_Employee&gt; _Employees = Employee.GetListOfActiveEmployees();

NSTextField value during edit is the field editors value. But I need the field's original value

objective-c cocoa osx

When I send stringValue to a NSTextField when it's field editor is active, it returns the current value from the field editor. But I need the original value from the NSTextField before it started