问题
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:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/21532704/code-first-migrations-what-connection-string-will-it-use