无法使用EntityFramework教程添加迁移

时间:2018-03-15 09:34:16

标签: c# migration identityserver4

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

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


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.

第一个执行没有问题,并且还将迁移添加到解决方案中。在使用第二个命令时,它告诉我构建失败,并出现以下错误: 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...] } } }

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

Program.cs - 扩展方法:

Main(...)

var host = BuildWebHost(args).Migrate(); host.Run(); 中调用扩展方法:

{{1}}

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

完成这些操作之后,在使用命令行成功添加第一次迁移后,我的解决方案中仍然存在相同的编译错误。

我在这里错过了什么吗?

干杯。

1 个答案:

答案 0 :(得分:2)

就我而言,我发现在/ Data / Migrations和/ Migrations处都有一个PersistedGrantDbContextModelSnapshot.cs *文件。其中之一需要删除。

*很明显,我的名字不同。