一、src下面增加DbMigrations类库,注意是要.Net Framework 类型的类库,不能是.Net Standard 的。
二、添加类库后为项目添加如上三个项目
appsetting.json 配置信息
{ "ConnectionStrings": { "AidenAdmin": "Server=127.0.0.1;port=3306;Database=AidenAdmin;User=root; Password=root" } }View Code
DbM_AidenAdminDbContext 上下文
namespace AidenAdmin.DbMigrations { [ConnectionStringName(AidenAdminDbProperties.ConnectionStringName)] public class DbM_AidenAdminDbContext : AidenAdminDbContext { public DbM_AidenAdminDbContext(DbContextOptions<AidenAdminDbContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }View Code
AidenAdminDbMigrationsContextFactory 上下文初始化文件
public class AidenAdminDbMigrationsContextFactory : IDesignTimeDbContextFactory<DbM_AidenAdminDbContext> { public DbM_AidenAdminDbContext CreateDbContext(string[] args) { var configuration = BuildConfiguration(); var builder = new DbContextOptionsBuilder<AidenAdminDbContext>() .UseMySql(ServerVersion.AutoDetect("AidenAdmin")); return new DbM_AidenAdminDbContext(builder.Options); } private static IConfigurationRoot BuildConfiguration() { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false); return builder.Build(); } }View Code
标签:AidenAdminDbContext,类库,DbM,AbpVnext,builder,AidenAdmin,添加,种子,public From: https://www.cnblogs.com/choii/p/18259882