AbpVnext系列<三> 添加种子项目
一、src下面增加DbMigrations类库,注意是要.Net Framework 类型的类库,不能是.Net Standard 的。
二、添加类库后为项目添加如上三个项目
appsetting.json 配置信息
{ "ConnectionStrings": { "AidenAdmin": "Server=127.0.0.1;port=3306;Database=AidenAdmin;User=root; Password=root" } }
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); } } }
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(); } }