Hrmmm I really like EF Code First, but I'm not sure if it fits what you are doing. How often does your circuit change?
Should you use EF?
EF Benefits
If the schema changes somewhat regularly, the Migrations part of EF Code First can save you a lot of time and effort, because you can often get rid of SQL scripts for schema updates - the schema changes end in your source repository, and the rest of your code. You will start here:
stack overflow
I also really like how easy it is to configure EF and how easy it is to write LINQ queries against it and return exactly the POCOs that I created from the database.
But EF may not be the best way.
Other ORMs to consider
Many other ORMs support LINQ and POCOs with better support for existing databases (there are things that can be quite difficult to display in EF Code First) - and existing support for asynchronous operation (EF is now at 5.0; has async) - (update: EF6 is the last one, and its support for async is great. Its massive removal is horrible, although it should be avoided like the plague, you need to switch to plain SQL).
In particular, NHibernate is a beast on stage for existing db support, but it's a bit of configuration complexity and what seems to be a political struggle has caused documentation that runs across different versions and forks.
Much simpler: " Micro ORMs " - this link has been shortlisted since 2011, but if you get bored you will find 30 or so .Net. Some generate better or less optimal queries, some of them are completely absent, some make you write SQL (do not use them) - you will have to poke to decide what is right for you. This may be a larger research task, but I suspect that a lightweight configuration and a small learning curve for one of these best suits that you are trying to do.
Answer your specific question
Talk to all client Dbs at once
If you simultaneously connect to all 50 databases from one application, you need to create an instance of 50 DbContexts, for example:
var dbClient1 = new DbClient1(); var dbClient2 = new DbClient2();
Assuming you walked around creating small wrapper classes, for example:
public class DbClient1 : CoreDbContext { public DbClient1() : base("DbClient1") // Means use the connection string named "DbClient1" in Web.Config
Where CoreDbContext is the main EF class in your project that extends DbContext (the standard part of any EF project).
Speak only one at a time
If you use only one application, any EF tutorial will be .
The only major trick is to migrate these Dbs when changing the schema. There are two main approaches. In any case, you take the backup and restore it locally so that you can test your migrations against them ( update-database -f -verbose ). If you do not compromise data errors, such as changing a column to NOT NULL, and looking for a local test instance does not have zeros, one client did, kaboom. Once you earn them, you decide how you want to update Production. There are many ways to do this, starting from writing a special fast-forward / rewind tool (or searching for it) using SQL scripts tested on git, hiring a database administrator, or much easier:
Obvious - SQL Script
Reset the migration to SQL ( update-database -script ) and run it with the actual production database.
My crazy way for small dbs numbers
Add entries for each db to Web.Config and create a project configuration for each of them, for example, "DbDeployClient1", "DbDeployClient2", etc. In each of them, create a construct, for example, DbDeployClient1, and then add it to your DbContext Class:
public CoreDbContext() #if DbDeployClient1 : base("DbDeployClient1") #elseif DbDeployClient2 : base("DbDeployClient2") // etc #endif {
This allows you to quickly switch to the DbDeploy configuration and migrate directly from Visual Studio to the target database. Obviously, if you do this, you need to temporarily open the port, it is advisable only to allow in your IP address the instance of SQL Server that you are transferring. One of the subtleties is that you get clear errors from your migration right there and complete rollback, without any real work - everything that supports rollback is part of EF. And one developer can do this without a bunch of other bottlenecks. But he has many opportunities to reduce risk and improve automation.