我有2个Visual Studio项目; .net核心Web API 3.1项目(用于ef迁移的启动)和包含dbcontext的类库。当我打开Powershell窗口时,导航到我的类库的文件夹,然后使用快照文件执行dotnet ef migrations add Initial --startup-project [path to csproj-file for the web API project]
迁移文件夹,并创建了初始迁移文件。
但是当我在Visual Studio中打开迁移文件时,出现了几个编译错误,其中一个抱怨The type or namespace 'Migrations' does not exist in the namespace 'Microsoft.EntityFrameworkCore'...
,我还可以看到自动生成的迁移文件包含指向Microsoft.EntityFrameworkCore.Migrations
的using语句,该语句被标记为不必要和msdn的文档清楚地包含了编译器引用的基础Migration
类和MigrationBuilder
类。
我尝试在Nuget.org上同时寻找Microsoft.EntityFrameworkCore.Migrations
和Microsoft.EntityFrameworkCore.All
,但都不存在。我在这里错过明显的东西吗?为什么自动生成的迁移文件无法编译?
显然,我对Migration类的msdn文档不够仔细。它位于Microsoft.EntityFrameworkCore.Relations
程序集中,在安装了Nuget软件包之后,该项目现在可以正确编译。