Entity Framework UWP 应用中的迁移找不到 ModelSnapshot

Entity Framework Migrations in UWP app can't find ModelSnapshot

对 UWP 应用程序 sqlite 使用 Entity Framework。一切都很好,但想为将来的更新添加迁移。

这里的步骤如下:

我能够添加一个迁移,它实际上创建了一个包含迁移和 SVContextModelSnapshot.cs 文件的迁移文件夹。一切似乎都很好。

现在,如果我进行更改(或不更改)然后 运行 Add-Migration Test,它会创建一个新的迁移,但就好像没有任何现有状态一样。它为每个模型创建一个 CreateTable 并从头开始重新创建整个数据库。这显然是错误的,我希望只看到我添加的单列。添加一个 -verbose 标签并没有显示出任何令人惊讶的东西。

执行“Remove-Migraiton”提示我遗漏了什么,因为它给出了错误

No ModelSnapshot was found.

查看 Remove-Mgiraiton -verboseAdd-Migration Test -Verbose,所有路径看起来都很好。快照文件就在那里。就是好像没用

Remove-Migration -verbose
Using project 'Data'.
Using startup project 'MigrationProj'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\dev\Sample\UWPApp\MigrationProj\bin\Debug\net6.0\MigrationProj.deps.json --additionalprobingpath C:\Users\SomeUser\.nuget\packages --additionalprobingpath "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages" --additionalprobingpath "C:\Program Files (x86)\Microsoft\Xamarin\NuGet" --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\dev\Sample\UWPApp\MigrationProj\bin\Debug\net6.0\MigrationProj.runtimeconfig.json C:\Users\SomeUser\.nuget\packages\microsoft.entityframeworkcore.tools.1.25\tools\netcoreapp2.0\any\ef.dll migrations remove --json --verbose --no-color --prefix-output --assembly C:\dev\Sample\UWPApp\MigrationProj\bin\Debug\net6.0\Data.dll --startup-assembly C:\dev\Sample\UWPApp\MigrationProj\bin\Debug\net6.0\MigrationProj.dll --project-dir C:\dev\Sample\UWPApp\Data\ --language C# --working-dir C:\dev\Sample\UWPApp --root-namespace Data
Using assembly 'Data'.
Using startup assembly 'MigrationProj'.
Using application base 'C:\dev\Sample\UWPApp\MigrationProj\bin\Debug\net6.0'.
Using working directory 'C:\dev\Sample\UWPApp\MigrationProj'.
Using root namespace 'Data'.
Using project directory 'C:\dev\Sample\UWPApp\Data\'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding Microsoft.Extensions.Hosting service provider...
No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'SVContext'.
Using context 'SVContext'.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.Sqlite'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.Sqlite'.
Finding design-time services referenced by assembly 'MigrationProj'.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'MigrationProj'...
No design-time services were found.
'SVContext' disposed.
Microsoft.EntityFrameworkCore.Design.OperationException: No ModelSnapshot was found.
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.RemoveMigration(String projectDir, String rootNamespace, Boolean force, String language)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.RemoveMigration(String contextType, Boolean force)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigrationImpl(String contextType, Boolean force)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigration.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
No ModelSnapshot was found.

问题已通过删除“.vs”文件夹并重新启动 VS 解决。