Multi project migration on code first

数据迁移的基本命令

如果把DBContext移动到子项目中,命令需要该

  • enable-migrations -ProjectName "dbcontext所在项目名" -ContextTypeName "dbcontext类名" -StartUpProjectName "启动项目名字" -Force

       PM> Enable-Migrations -ProjectName ClassLibrary1 -ContextTypeName Model1 -StartUpProjectName ConsoleApp1 -Force

Checking if the context targets an existing database...
Code First Migrations enabled for project ClassLibrary1.
PM>

  • add-migration -ProjectName "dbcontext所在项目名" createdatabase
  • update-database -ProjectName "dbcontext所在项目名"

PM> Update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
No pending explicit migrations.
Applying automatic migration: 202005041138034_AutomaticMigration.
Running Seed method.
PM> Update-database

子项目进行数据迁移的问题

如果在子项目中app.config中加入connectstring,去改变默认的链接,而且要注意connectstring放的顺序

 

posted @ 2020-04-18 00:51  devs  阅读(162)  评论(0编辑  收藏  举报