At runtime, can Entity Framework connect to several databases (with the same schema)?

asp.net asp.net-mvc entity-framework

Question

First of all, let me state I'm very new to EF. With that said, here's my dilemma:

There will be an ASP.NET App migrated to ASP.NET MVC. I would like to utilize EF for this. There is one main database which stores "client information". Apart from that, every "client" has their own database. These are the constraints we have.

Currently, client information in the main DB that enables me to build a connection string per client and make individual SQL calls.

How would I accomplish the same thing in Entity Framework? Each database WILL have the same schema. Is there a way to programmatically switch the Connection String? These DBs are currently on the same server, but that's not a requirement and it may be a completely different server.

Any ideas?

Multiple connection strings in the Web.config would be a last resort. Even then, I'm not sure how exactly to wire this up.

Thank you in advance.

1
23
8/10/2009 8:56:35 PM

Popular Answer

If you work through an EntityConnection in the constructor of your entities object, you can change the database pretty easily.

EntityConnection con = new EntityConnection(connString);
con.ChangeDatabase(dbName);
using (Entities context = new Entities(con))
{
    // Some code here
}
8
8/10/2009 9:53:01 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow