添加 nuget 包:

  1. Microsoft.EntityFrameworkCore.Design
  2. Microsoft.EntityFrameworkCore.SqlServer
  3. Microsoft.EntityFrameworkCore.Tools

继承接口:

IDesignTimeDbContextFactory<XXDbContext>

实现接口:

        public XXDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<XXDbContext >()
.UseSqlServer(_dbConnectionString, builder =>
builder.MigrationsAssembly(typeof(Program).Namespace)); return new XXDbContext (optionsBuilder.Options);
}

 

efcore-cli (command bat 放在了 "ef-cli" 文件夹下面):

migrations :
cd ..
rmdir /S /Q Migrations dotnet ef migrations add InitialXXDbContextMigration -c XXDbContext -o Migrations/XXDb dotnet ef migrations script -c XXDbContext -o Migrations/XXDb.sql cd ef-cli
update db:
cd ..
dotnet ef database update -c XXDbContext
cd ef-cli
drop db:
cd ..
dotnet ef database drop -c XXDbContext
cd ef-cli

  

efcore 控制台迁移架构的更多相关文章

  1. EFCore数据库迁移命令整理

    前言  因为现在用.net core 开发新项目,过程中需要经常涉及到数据命令的迁移,今天分别整EFCore 的两种迁移数据库的方式 1 程序包管理器控制台 , Package Manager Con ...

  2. Entity Framework Code First 多数据库 控制台迁移代码

    1.启动迁移 Enable Migrations Enable-Migrations -MigrationsDirectory "MigrationsOne" -ContextTy ...

  3. EFCore自动迁移

    2019/05/14,EFCore 2.2.4 有两种方式: 使用Migrate()方法 if (DbContext.Database.GetPendingMigrations().Any()) { ...

  4. .net core EFCore CodeFirst 迁移出现错误【No project was found. Change the current working directory or use the --project option. 】

    PM> dotnet ef Migrations add Init No project was found. Change the current working directory or u ...

  5. ASP.NET Core搭建多层网站架构【5-网站数据库实体设计及映射配置】

    2020/01/29, ASP.NET Core 3.1, VS2019, EntityFrameworkCore 3.1.1, Microsoft.Extensions.Logging.Consol ...

  6. EntityFrameworkCore数据迁移(一)

    .net core出来已经有很长一段时间了,而EentityFrameworkCore(后面简称EFCore)是.net framework的EntityFramework在.net core中的实现 ...

  7. Windows Server 2016-图形化迁移FSMO角色

    上章节我们简单介绍了三种不同方式查看FSMO主机角色信息,在开篇之前我们简单回顾一下FSMO五种操作主机角色:林范围操作主机角色有两种,分别是 架构主机角色(Schema Master)和 域命名主机 ...

  8. efcore分表分库原理解析

    ShardingCore ShardingCore 易用.简单.高性能.普适性,是一款扩展针对efcore生态下的分表分库的扩展解决方案,支持efcore2+的所有版本,支持efcore2+的所有数据 ...

  9. 不同场景下 MySQL 的迁移方案

    一 目录 一 目录 二 为什么要迁移 三 MySQL 迁移方案概览 四 MySQL 迁移实战 4.1 场景一 一主一从结构迁移从库 4.2 场景二 一主一从结构迁移指定库 4.3 场景三 一主一从结构 ...

随机推荐

  1. xth 的玫瑰花(codevs 1360)

    题目描述 Description 这天是rabbit 的生日前夕,Xth 来到花店,要给他的rabbit 买玫瑰花,为了保证质 量,他跟花店老板——小菜儿同学要求自己到花田采摘.小菜儿灰常希望早日见到 ...

  2. 【ACM】nyoj_106_背包问题_201308152026

    背包问题时间限制:3000 ms  |  内存限制:65535 KB 难度:3描述 现在有很多物品(它们是可以分割的),我们知道它们每个物品的单位重量的价值v和重量w(1<=v,w<=10 ...

  3. HDU2037 事件排序问题

    题目要求: Problem Description "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!&q ...

  4. oc32--构造方法1

    // // Person.h #import <Foundation/Foundation.h> @interface Person : NSObject @property int ag ...

  5. the user must supply a jdbc connection 错误解决方法

    转自:https://blog.csdn.net/actionzh/article/details/54200451 今天在配置hibernate之后,进行添加数据测试时,运行中报出了 the use ...

  6. (Go)07.strings与strconv的示例

    package main import ( "strconv" "fmt" "strings" ) func main() { str := ...

  7. hdu5249

    这个是去年astar的题~ 标准做法主席树,然而渣渣并不会(我确实叫zhazha...), 所以,他先离线,离散化,然后树状数组+二分水过了.... 离线的目的主要是为了离散化,剩下的就和用一个树状数 ...

  8. Appium + python - get_attribute获取value操作

    from appium import webdriverfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium.w ...

  9. selenium3 + python - expected_conditions判断元素

    expected_conditions 类 title_is: 判断当前页面的title是否完全等于(==)预期字符串,返回布尔值 title_contains : 判断当前页面的title是否包含预 ...

  10. 手写DAO框架(一)-从“1”开始

    背景: 很久(4年)之前写了一个DAO框架-zxdata(https://github.com/shuimutong/zxdata),这是我写的第一个框架.因为没有使用文档,我现在如果要用的话,得从头 ...