EntityFrameworkCore 如何从 Visual Studio Code (VSCode) 运行"Update-Database"和"Add-Migration"



我正在尝试在Visual Studio Code中的EntityFrameworkCore,我想运行"Update-Database"one_answers"Add-Migration "命令,但在VSCode中没有包管理器控制台。该怎么办?

是的,您总是可以对vscode这样做。

执行上述命令安装dotnet ef tool

dotnet tool install --global dotnet-ef

您应该在命令提示符中得到如下消息:

可以通过以下命令调用该工具:dotnet-ef tool'。net-ef'(版本'5.0.3')已成功安装。

现在您应该能够运行任何ef命令。例如,

dotnet ef database update

这将给你一个如下的响应。

构建开始……

构建成功。

只是分享这个,因为有些人可能没有安装ef工具。

Visual Studio Code不支持运行包管理器控制台命令。这种集成只在Visual Studio中可用。您将不得不使用命令行接口(CLI):

http://www.learnentityframeworkcore.com/migrations/commands/cli-commands

你完全可以从VS Code终端运行EF命令。首先,确保您在包含"appsettings"的目录中。你的"Program.cs"等

尝试执行dotnet ef database update您可能会得到"运行"dotnet工具恢复"以使"dotnet-ef"命令可用。输入:dotnet tool restore然后再试试dotnet ef database update

添加迁移:

dotnet ef migrations add ChosenMigrationName

以下是在vscode中EF代码优先项目所需的命令列表。

dotnet new webapi 
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.EntityFrameworkCore.Tools
dotnet ef migrations add InitialDatabase
dotnet ef database update

最新更新