Code first migrations - what connection string will it use?

code-first connection-string ef-migrations ef-model-first entity-framework

Question

Code first migrations have been working very well for me. I have a services project and a wpf project. The model is in the services project which is referenced by the wpf project. Update-database is done on the services project, but uses connection string from the wpf project. I now add a web project which also references the service project. So now that there is a connection string in the app.config and there is one in the web.config, which one will it use?

1
15
2/3/2014 4:38:43 PM

Accepted Answer

In my scenario, the app.config in the services project is ignored. Code first migrations will use either the app.config from the WPF project or the web.config on the web project, depending which is selected as the startup project.

40
2/4/2014 3:09:31 PM

Popular Answer

When doing update-database you should specify the project that contains the migrations. Make sure that you have an app.config file in that project that contains the correct connection string.
you can do a Update-Database -ConnectionStringName "MyConnectionString" and it should work like a charm.



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