ASP.Net Core 3.1 Web APIApiController,EF Core 3.1 {系统找不到指定的文件}

问题描述

我之前已经做过几个.net核心api的EF核心。实际上,我在https://github.com/xmione/.Net-Core-2.2处创建了一个有效的.Net Core 2.2版本。

现在,我尝试为核心api和ef核心同时执行核心3.1。每个当然都有单独的项目。 我可以做添加迁移和更新数据库数据库和表将自动创建。我还可以访问weatherforcast api方法,它可以完美显示数据。 UseInMemoryDatabase的效果也很棒。但是当我开始使用UsesqlServer()时。那是我遇到错误的时候:

Win32Exception: The system cannot find the file specified.
UnkNown location

sqlException: A network-related or instance-specific error occurred while establishing a connection to sql Server. The server was not found or was not accessible. Verify that the instance name is correct and that sql Server is configured to allow remote connections. (provider: SNI_PN11,error: 52 - Unable to locate a Local Database Runtime installation. Verify that sql Server Express is properly installed and that the Local Database Runtime feature is enabled.)
Microsoft.Data.sqlClient.sqlInternalConnection.OnError(sqlException exception,bool breakConnection,Action<Action> wrapCloseInAction)

我可以在Visual Studiosql Server Management Studio中看到创建的数据库和表,并且可以使用它来进行创建,添加,编辑和删除记录。但是当我运行API并对其进行测试时。它失败并显示上面的错误。 有人可以指出我在这里最快的方向。谢谢。我的代码位于以下链接

https://github.com/xmione/ReactJS/tree/master/ReactJS.Redux.Web.API/API

非常感谢!

解决方法

我只是想出了解决方法。我只是关注https://code-maze.com/net-core-web-api-ef-core-code-first/上的文章。 Github.com上实际上有一个源代码:https://github.com/CodeMazeBlog/ef-code-first

我只是关注本文,下载源代码并将其与我的代码进行比较。我发现我缺少一些重要的存储库类。

由于那篇文章,我在Github.com中的代码已经修复。 我的Web API源代码位于: https://github.com/xmione/ReactJS/tree/master/ReactJS.Redux.Web.API 我希望这会对需要它的人有所帮助。