I have a 3-tier architecture project (Web, Service, DataAccess), I just want to migrate the database to latest version whenever POCO changes happen. We can do this by calling the automatic migration code from
Application_Start event. In this scenario, I don't have the reference of the
DataAccess project in my web. So how can I call the automatic migration code from
Database.SetInitializer(new MigrateDatabaseToLatestVersion<BlogContext, Configuration>());
I can't access the
Please help me
Thanks in advance [In Production environment, we can't run update-database command thru VS, so is there any other way to update the database automatically)
You should be generating scripts from migration to be executed in the production. What works for me is to use Update-Database -Script
That creates a script with a 'migration difference', which you can manually apply as an SQL script on the target server database (and you should get the right migration table rows inserted etc.).
Personally, I don't trust automatic updates in 'live' scenarios, and I always prefer manual database administration (i.e. there is a problem with permissions needed to create or alter Db - not to mention shared hosting etc.) - but from what I've seen migrations are pretty solid when it comes to synchronizing (in fact, the only way to 'untie' them normally is to remove the Db and force full/fresh update). Hope that helps.