How to UPDATE DATABASE in Code First approach automatically after check-in and Publish code in Continuous deployment

耗尽温柔 提交于 2019-12-06 21:04:39

You can try to run Add-Migration/Update Database commands in the build/deploy process.

Assume you are using vNext build,

  1. Add a "Nuget Installer" task in your build definition first to restore the Entity Framework during the build. Migrate.exe will be installed in \packages\EntityFramework.\tools folder.
  2. Then add a "Command Line" task to run the migrate.exe. Enter “\packages\EntityFramework.\tools\migrate.exe" in "Tool" area and the arguments in "Arguments" field.

Reference this thread : How can I run Entity Framework's migrate.exe from Visual Studio Online?

You can also try the extension "Entity Framework Migrations" which contains a set of tasks which allow you to work with Entity Framework code first migrations:

Method 1: Generating SQL script

The first method allows you to generate a SQL script containing all migrations. This script can be obtained by manually running Update-Database -SourceMigration 0 -Script in the NuGet package manager console in Visual Studio. You can then either manually run this script after the release or automatically during the release using a extension that allows you to run SQL scripts.

Task name: Generate migration SQL script

Other articles may helps:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!