VS2017 + ReactJS +使用实体框架抛出和迁移错误

时间:2017-08-25 11:32:31

标签: entity-framework reactjs react-redux asp.net-core-2.0 .net-core-2.0

我在VS2017(.net core 2.0)中启动了一个新的React + Redux项目。默认模板没有数据库使用,所以我只是手动添加了实体框架的使用。它编译得很好,但是当我尝试使用命令

添加迁移时
dotnet ef migrations add "Initial"

我收到了下一个错误:

An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: One or more errors occurred. (Webpack dev middleware failed because of an error while loading 'aspnet-webpack'. Error was: Error: Cannot find module 'aspnet-webpack'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\sibvic\AppData\Local\Temp\iu25u5dg.r0n:83:19)
at __webpack_require__ (C:\Users\sibvic\AppData\Local\Temp\iu25u5dg.r0n:20:30)
at createWebpackDevServer (C:\Users\sibvic\AppData\Local\Temp\iu25u5dg.r0n:62:26)
at C:\Users\sibvic\AppData\Local\Temp\ftqvg4wq.l1l:114:19
at IncomingMessage.<anonymous> (C:\Users\sibvic\AppData\Local\Temp\ftqvg4wq.l1l:133:38)
at emitNone (events.js:86:13)
Current directory is: C:\projects\test\bin\Debug\netcoreapp2.0
)
Unable to create an object of type 'ApplicationDbContext'. Add an implementation of 'IDesignTimeDbContextFactory<ApplicationDbContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.

看起来这个功能太新了。我找不到太多信息。并且无法弄清楚自己出了什么问题(至少橡皮鸭方法也不起作用)。

知道怎么解决吗?

1 个答案:

答案 0 :(得分:1)

从dotnet核心1.1迁移到2.0期间,我遇到了同样的问题。

我必须将我的Program类的实现更新为以下内容:

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .Build();
}

我知道这不是关于React + Redux,但也许它可以帮助你。