I have an MVC3 Application that allows a user to choose the database they want to use on initial login. The various connection strings are available in the web.config I would like every DataContext to use the chosen connection.
I am aware that I can supply a parameter to one instance of a named DataContext l开发者_JAVA百科ike this:
MyDataContext db = new MyDataContext(ConnectionString);
or I can override the OnCreated event for all instances of a named DataContext
public partial class MyDataContext
{
partial void OnCreated()
{
Connections connections = new Connections();
this.Connection.ConnectionString = connections.GetCurrentConnectionString();
}
}
how about all instances of all DataContexts throughout the application?
精彩评论