宇宙超能无敌之饼干怪

首页 新随笔 联系 管理

ef core自定义默认的迁移表的名称

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace Long.EntityFrameworkCore;

class MyDesignTimeDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
{
    public ApplicationDbContext CreateDbContext(string[] args)
    {
        DbContextOptionsBuilder<ApplicationDbContext> builder = new();
        string connStr =
            "Data Source=localhost;Initial Catalog=test31;User ID=sa;Password=xxxxxx;Trust Server Certificate=True";
                                                                       //👇 :默认迁移表名称    👇架构 
        builder.UseSqlServer(connStr,x=>x.MigrationsHistoryTable("__EFMigrationsHistory_Book","dbo"));
        return new ApplicationDbContext(builder.Options);
    }
}
posted on 2024-06-20 21:55  lazycookie  阅读(5)  评论(0编辑  收藏  举报