With entity framework, could I, say at fairly high up in the stack set which database I want to connect to, and then have EF use that for all queries?
This is not a scenario where you have a different db per model, but rather have开发者_运维技巧 all models connect to the same database, but this database could be different depending on some criteria (like say the URL or a sub-domain).
If yes, what implications would this have with db pooling etc?
When you create your ObjectContext, a parameter for the constructor is the connection string:
http://msdn.microsoft.com/en-us/library/bb739017.aspx
There should be no implications on pooling.
Yes you can do this. It's simply a matter of using the proper connection string when creating your ObjectContext, that connects you to the database you want to use. We do this frequently.
Everytime you use your DbContext
you can simply change the connectionString before you do any queries.
For Example, you can simply change the Initial Catalog name:
YourDbContext.Database.Connection.ConnectionString = "data source=LAPKEVIN\\SQLKEVIN;Integrated Security=SSPI;Initial Catalog=YourDatabase";
精彩评论