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?
Code First Migrations allow you to create a new database or update an existing database based on your model classes using the Package Manager Console for running commands. If you are using the EF code first approach then there are more ways to initialize the database provided by the Entity Framework as follows.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With