I've got a program that has one .edmx file and in the app.config has three connection strings.
The schema that the .edmx represents is the same for 3 databases:
- Production
- Staging
- Development
and I want to make a method that basically does this (warning! Pseudo-code incoming)
foreach(var connectionString in connectionStrings) {
using (MyCustomDBEntities context = new MyCustomDBEntities(connectionString)) {
// Do cool things, like insert new records, update records, etc...
}
}
Right now the code that I have is actually this, I don't see another method signature that accepts a connections string:
foreach(var connectionString in connectionStrings) {
using (MyCustomDBEntities context = new MyCustomDBEntities()) {
// Do cool things, like insert new records, update records, etc...
}
}
Is there a way to make my Entity Framework constructor in the using block take a connection string? I'm using EF 6.1 right now and I can't find a way.
Also if there is a better way to do this with Entity Framework I'm happy to switch my code around although using Entity Framework is a must.
If you need more code please let me know and I'll update with anything.