Rollback Migration – If we want to rollback our database schema to any previous migration state then we can use the update-database command with the -TargetMigration parameter. The Up() function contains the code for creating the database and Down() function contains the code for dropping or deleting the database objects.įor help with any command, we can execute a command get-help Up and down functions in the migration file Update-database – This command will execute the last migration created by the add-migration command.This command will create a new file with _.cs Add-migration – It adds all the changes in the models in the up and down functions in the new migration file.Enable-migration – This command enables the migration for our project by creating the Migration folder and Configuration class.There are 2 ways to do the migration in code first –Ģ.Automated Migration Code-based Migrationįor code migration, we need to use the following commands in the Nuget Package manager console in visual studio – Initially, we need to create the domain classes having the properties and then we create the database according to the domain classes.ĭatabase Migration – Migration is used to update the database schema as our domain classes change. While this example specifies the connection string directly, the connection string can also be stored as a configuration variable, in a configuration file, or omitted if the artifact already contains a configuration file (or one was deployed with Deploy-ConfigFile) with a valid connection string.In code first approach we create the domain classes first rather than creating the database. Assuming it was captured in an artifact, the deployment plan only requires the following operations: Deploy-Artifact Database() Įxec ef6.exe database update -assembly -connection-string "Database=MyProject Server=us-db-stg-01 Integrated Security=true" To perform a migration in a BuildMaster deployment plan, simply use the Exec operation against ef6.exe. An optional -target migration name may specified, which will only run migrations up to and including the specified one by name. This command will run all migrations in the assembly against the MyProject database. To migrate a database from a compiled DLL that contains code-first migrations, an example command would be: ef6.exe database update -assembly -connection-string "Database=MyProject Server=us-db-stg-01 Integrated Security=true" This is likely the best solution if all the migrations are executed on the same server (regardless of the actual server the database is on or specified in the connection string). This can be accomplished in a build plan like this: NuGet::Restore-Packagesįrom: ~\src\packages\EntityFramework.\tools\\Īlternatively, you could store ef6.exe on the build server in a directory referenced in the Windows PATH. Refer to the linked documentation for the arguments.įor ease of deployment, we recommend capturing the ef6.exe tool into a database build artifact alongside the DLL that contains the migrations. Prior to EF v6.3.0, the tool migrate.exe was used to perform migrations. Refer to the dotnet ef CLI documentation for more information on the specific arguments. Any commands that reference ef6.exe can be replaced with dotnet.exe ef, although the arguments are slightly different. NET Core applications do not require this tool, as it is included with the dotnet.exe CLI. zip, and extracting it from the tools// directory. zip files, the executable can be extracted directly from the package in Windows by downloading the package, changing the extension from. Because it is a standalone tool and NuGet packages are. The ef6.exe command line tool is found in the tools/ subfolder of the EntityFramework NuGet package. NET Core CLI tool, or the standalone tool ef6.exe.Īs an alternative to migrations, change scripts could be generated and executed using BuildMaster's built-in change script management process. Migrations can be performed directly from Visual Studio, the. NET objects after the database schema is created) may be the best solution.īuildMaster is capable of deploying database changes resulting from changes to the ORM objects. For those organizations, scaffolding (i.e., generating the. This process, known as a code first, can increase the development cycle in smaller organizations, but also introduce deployment challenges in larger organizations where specialized teams perform database deployments. NET applications, allowing devlopers to effectively build database schemas in any platform (e.g., SQL Server, MySQL, PostgreSQL) in C# or Visual Basic, as opposed to creating them by writing SQL directly. Entity Framework (EF) is Microsoft's ORM designed for.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |