将dotnet core 2.1
应用升级到dotnet core 3.1
后,我无法创建新的迁移。这是我的配置:
我的启动看起来像:
public void ConfigureServices(IServiceCollection services) {
services.AddOptions();
services.AddDbContext<DataContext>(options => {
var connectionString = Configuration.GetConnectionString("DefaultConnection");
options.UseNpgsql(connectionString);
});
// other configurations
}
public void ConfigureContainer(ContainerBuilder builder) {
// register my services in autofac
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env){
// configure stuff
}
和程序:
public static IHostBuilder CreateHostBuilder(string[] args)
=> Host.CreateDefaultBuilder(args)
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
这是我的DbContext
:
public class DataContext : DbContext {
public DataContext(DbContextOptions<DataContext> options):base(options) {}
}
现在,当我运行此命令时:
dotnet ef migrations add Initial
我收到此错误:
在激活特定注册期间发生错误。 有关详细信息,请参见内部异常。注册:激活器= DbContextOptions [](DelegateActivator),服务= [System.Collections.Generic.IEnumerable
1[[Microsoft.EntityFrameworkCore.DbContextOptions, Microsoft.EntityFrameworkCore, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]]], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = DbContextOptions (DelegateActivator), Services = [Microsoft.EntityFrameworkCore.DbContextOptions], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = DbContextOptions
1 (DelegateActivator),服务= [Microsoft.EntityFrameworkCore.DbContextOptions`1 [[Manex.Micro.Auth.Data.DataContext, Manex.Micro.Auth,版本= 1.0.0.0,文化=中性, PublicKeyToken = null]]],生命周期= Autofac.Core.Lifetime.CurrentScopeLifetime,共享=共享, 所有权= OwnedByLifetimeScope --->类型中的方法'get_Info' 'Microsoft.EntityFrameworkCore.Infrastructure.Internal.NpgsqlOptionsExtension' 来自程序集'Npgsql.EntityFrameworkCore.PostgreSQL,Version = 1.1.0.0, 文化=中性,PublicKeyToken = 5d8b90d52f46fda7'没有 实施。 (有关详细信息,请参阅内部异常。)(请参阅内部 有关详细信息,请参见异常。)(有关详细信息,请参阅内部异常。)
我从程序集'Npgsql.EntityFrameworkCore.PostgreSQL 中搜索了类型为'Microsoft.EntityFrameworkCore.Infrastructure.Internal.NpgsqlOptionsExtension'的方法'get_Info',但是没有任何结果。你知道我在做什么错吗?
这是我的书库堆栈:C#
,ASP.NET Core 3.1
,.NET Core 3.1
,NPGSQL
,Autofac
。
更新:
我删除了Autofac
,并将DbContext
更改为带有一个简单实体的简单上下文。现在,我得到的唯一错误是:
方法“ get_Info”的类型 'Microsoft.EntityFrameworkCore.Infrastructure.Internal.NpgsqlOptionsExtension' 来自程序集'Npgsql.EntityFrameworkCore.PostgreSQL,Version = 1.1.0.0, 文化=中性,PublicKeyToken = 5d8b90d52f46fda7'没有 实施。