在将我的项目迁移到.NET Core 2.0,全新安装Visual Studio 15.5和.NET CORE sdk 2.1.2之后,我在尝试使用EF Core添加迁移时出错 .
C:\Projects\SQLwallet\SQLwallet>dotnet ef migrations add IdentityServer.
An error occurred while calling method 'BuildWebHost' on class 'Program'.
Continuing without the application service provider. Error: Parameter count mismatch.
Done. To undo this action, use 'ef migrations remove'
因此,将创建一个空的迁移类,其中包含空的Up()和Down()方法 .
program.cs看起来像:
public class Program
{
public static IWebHost BuildWebHost(string[] args, string environmentName)
{...}
public static void Main(string[] args)
{
IWebHost host;
host = BuildWebHost(args, "Development");
请指教 . 在Core 1.0上,迁移工作正常 . 我实现了IDesignTimeDbContextFactory,而我的DBContext类有一个无参数构造函数,所以它不是原因 .
2 回答
看一下DbContext中的OnModelCreating方法 . 确保它调用
base.OnModelCreating(builder)
. 它应该看起来像:如果您使用
builder.Entity<T>().HasData(...)
为数据设定种子,请确保将其传递给T []而不是IEnumerable .我的解决方案是将Array传递给
HasData
函数,而不是通用List
. 如果使用List,请尝试使用ToArray
函数转换数组 .