We have an Entity framework 4.1 setup, auto generated POCOs and DbContext classes for interaction with the db.
The automatically generated DbContext derived class looks like this:
public MyEntities()
: base("name=MyEntities")
{
}
And the automatically generated connection string in app.config something like:
<connectionStrings>
<add name="MyEntities" connectionString="blah blah blah" providerName="System.Data.EntityClient" />
</connectionStrings>
That's all fine, and works right out of the box.
Each of our developers has their own SQL Developer edition install for unit testing and dev purposes, so they need to modify the connection string to point to their installation when doing unit testing. These connection strings are in the App.config file of the unit test project
This is currently a manual modification step, and I had thought to automate this in some way.
Now, I can go and work out the connection string in code, but passing this into the entity framework constructor is prevented by the default auto-generated "MyEntities" constructor above - it doesn't have a connection string parameter on any constructor. (Although DbContext does). Furthermore, I don't particularly want to plumb the connection string through the DAL code and down into the entity framework code - that isn't needed in production, so that's modifying my code just for the purposes of unit test.
I had thought there must be some way to override the string in App.config.
This would be similar to how this can be done with a local Appsettings file.
(ie <appSettings file="Local.config"/>)
, but I can't seem to see how to do this for the ConfigurationManager.ConnectionStrings entries.
So, what does one do here?