问题描述
我一直在使用
dotnet ef --startup-project "../WebApp/WebAppProject/" migrations add migrationName
要生成迁移,但是在将EF Core版本从2.1升级到3.1之后,它开始引发如下错误:
An error occurred while accessing the Microsoft.Extensions.Hosting
services.
Continuing without the application service provider.
Error: Problem with determining the path to the folder storing the application files
System.MissingMethodException: Method not found: 'Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder`1.HasIndex(System.Linq.Expressions.Expression`1<System.Func`2<System.__Canon,System.Object>>)'.
at
位于{p的base.OnModelCreating(builder);
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.ApplyConfigurationsFromAssembly(typeof(Context).Assembly);
}
我的项目/文件夹结构
Container
|
|
|----- Common (project) (here I'm executing above mentioned command as I used to do it)
|
|
|
|----- Persistence
|
|
| Context.cs
| ----- Migrations
|
| Migration1.cs
| Migration2.cs
| Migration3.cs
| ....cs
|
| ----- WebApp
| ----- WebAppProject (project)
| WebApp.csproj
| Startup.cs
| Program.cs
DesignTimeDbContextFactory
类位于Program.cs
内的WebApp/WebAppProject/
中
一般来说,路径是好的,没有任何变化,并且一直在工作,但是在升级版本后,我不确定如何帮助该工具 发现我的数据库
dotnet工具列表--global 3.1.7 dotnet-ef
解决方法
确切的命令可以有效地解决您的解决方案结构,除非您引用了某些旧库版本或正在使用某些旧的EF Core CLI版本。
请确保所有对EF Core库的引用都是最新的(表示3.1.7),并且EF Core工具也安装了相同版本。
(如果您认为已经存在,请随时发布项目文件的内容和EF Core CLI命令的--verbose
输出。)