迁移错误 - 无法构建DirectConstructorBinding类型的文字

RHa*_*ris 5 ef-core-2.0

我正在跟随Julie Lerman的Pluralsight课程 - EntityFramework Core 2: Getting Started.在这门课程中,她有3个项目.前两个DataDomain是基于.NET标准库.第三个项目Web是.NET Core Web应用程序.

我遵循了这个结构.在Data我添加了一个名为Client的POCO类.

Domain我添加了一个名为TestDbContext的类,如下所示:

public class TestDbContext : DbContext
{
    public DbSet<Client> Clients { get; set; }

    public TestDbContext(DbContextOptions<TestDbContext> options) : base(options)
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

在她的示例之后,我在Web项目的Startup.cs中执行了以下操作,将提供程序和连接字符串注入DbContext.

public void ConfigureServices(IServiceCollection services)
{
   services.AddMvc();
   services.AddDbContext<TestDbContext>(options =>
   {
       options.UseSqlServer(Configuration.GetConnectionString("TestConnection"));
   });
}
Run Code Online (Sandbox Code Playgroud)

最后,我尝试向此上下文添加迁移.我将Web项目设置为启动项目.在Package Manager控制台中,我输入add-migration initial.

然后我得到以下错误: The current CSharpHelper cannot scaffold literals of type 'Microsoft.EntityFrameworkCore.Metadata.Internal.DirectConstructorBinding'. Configure your services to use one that can.

在朱莉的视频中,这一切都为她工作,并创建了迁移包.但是,对我来说 - 只是错误.关于可能发生的事情的任何线索?

小智 10

在".csproj"文件中检查项目的包版本.以前我对AspNet CoreEntityFramework Core的版本mitch匹配有同样的问题(我猜).为我做同样的工作很好.找到解决方案在这里

对我来说吧.

<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0-rc1-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0-rc1-final" PrivateAssets="All" /> 
Run Code Online (Sandbox Code Playgroud)


小智 5

从nuget软件包管理器中添加3个具有相同版本的软件包

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.2" />
Run Code Online (Sandbox Code Playgroud)