无法使用 EntityFramework 教程添加迁移

Ala*_*ain 2 c# migration identityserver4

我目前正忙于使用他们文档页面上教程的EntityFramework部分来集成 Identity Server 4 。我的项目使用 .NET Core 2.0。

一切顺利,直到它告诉我使用命令行添加迁移。这些命令是:

dotnet ef migrations add InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb
dotnet ef migrations add InitialIdentityServerConfigurationDbMigration -c ConfigurationDbContext -o Data/Migrations/IdentityServer/ConfigurationDb
Run Code Online (Sandbox Code Playgroud)

第一个执行没有问题,并将迁移添加到解决方案中。使用第二个命令时,它告诉我构建失败,并出现以下错误: 1>Migrations\IdentityServer\PersistedGrantDb\PersistedGrantDbContextModelSnapshot.cs(13,6,13,15): error CS0579: Duplicate 'DbContext' attribute 1>Migrations\IdentityServer\PersistedGrantDb\PersistedGrantDbContextModelSnapshot.cs(16,33,16,43): error CS0111: Type 'PersistedGrantDbContextModelSnapshot' already defines a member called 'BuildModel' with the same parameter types 1>Done building project "IdentityServer.csproj" -- FAILED.

现在,在阅读了一些其他文章和这个公告后,(设计时)DbContext 发现似乎已经改变了。为了解决这个问题,我更改了一些代码。相关部分(据我所知):

Program.cs - 扩展方法:

 public static IWebHost Migrate(this IWebHost webhost)
 {
    using (var scope = webhost.Services.GetService<IServiceScopeFactory>().CreateScope())
    {
        scope.ServiceProvider.GetService<PersistedGrantDbContext>().Database.Migrate();

        using (var dbContext = scope.ServiceProvider.GetRequiredService<ConfigurationDbContext>())
        {
            dbContext.Database.Migrate();
            [etc...]
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在 中调用扩展方法Main(...)

var host = BuildWebHost(args).Migrate();
host.Run();
Run Code Online (Sandbox Code Playgroud)

此外,我已经从Startup.cs 中删除了InitializeDatabase方法。

完成这些事情后,在使用命令行成功添加第一次迁移之后,在我的解决方案中几乎仍然会出现相同的编译错误。

我在这里错过了什么吗?

干杯。