WPF使用EFCore无法使用迁移
.net core wpf项目使用efcore时,会遇到无法进行迁移的问题,找到的解决办法如下:
①在入口程序安装Microsoft.EntityFrameworkCore.Design包。
②在数据库上下文项目添加一个实现IDesignTimeDbContextFactory接口的类
例如:
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<SqliteDbContext>
{
public SqliteDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<SqliteDbContext>();
return new SqliteDbContext(optionsBuilder.Options, null);
}
}
Comments
Be the first to post a comment