Issue
I have an existing ASP.NET Core Angular Web application with the usual flairs. It comes with set of migration scripts (e.g. 20151227555555_AddIdentity.cs, 20161227444444_AddCoreEntities.cs etc) in a Migration/ code folder, each has Up, Down, and BuildTargetModel methods.
then there is another folder called MigrationScript that contains the equivalent of table creation SQL scripts (straight-up CREATE TABLE...) for the various database entities.
I am used to running database management and recreation/restore via a database project that I can "publish". I am new to the EF Migration way of doing it, so how do I run those migration C# scripts to create the database?
Solution
The fact that the C# migration scripts already contains Up() and Down() methods means they are ready to be applied. (Note: usually the Up and Down methods are created by the Add-Migration migrationname command).
Here is how to apply the C# entity framework migration scripts in an existing project:
Create the empty database with the correct database name. The database name is usually defined in the
aspsettings.jsonfile underConnectionStringsgroup. Open Microsoft SQL Server Management Studio, create an empty database with the correct name.In Visual Studio Solution Explorer, right-mouse click on the project that contains the
Migrationfolder (where the C# migration scripts are located), chooseManage NuGet Packages...and look underInstalledtab to see ifMicrosoft.EntityFrameWorkCore.Toolspackage is installed, if not go ahead install it. Because that is the package that contains the EF migration commands, i.e.Add-Migration,Update-DatabaseetcWith the
Microsoft.EntityFrameWorkCore.Toolspackage installed in the project that contains theMigrationfolder, open thePackage Manager ConsoleviaTools -> NuGet Package Manager -> Package Manager Consolemenu options.At the
Package Manager Consoleprompt, type the commandUpdate-Database, then all of the migration scripts will be applied and the tables created in the local SQL Server database created in step 1.
Answered By - For Comment Answer Checked By - Katrina (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.