'AddEntityFramework*' 在服务提供者上被调用,但 'UseInternalServiceProvider' 没有在 DbContext 选项配置中被调用

'AddEntityFramework*' was called on the service provider, but 'UseInternalServiceProvider' wasn't called in the DbContext options configuration

我正在将 ASP.NET 核心应用程序从 Framework 2.2 升级到 3.1。它还使用 Entity Framework 核心。

在Startup.ConfigureServices方法中,有这段代码:

services.AddEntityFrameworkNpgsql()
    .AddDbContext<MainDbContext>(options => options
        .UseNpgsql(Configuration.GetConnectionString("MainDbContext")));

.NET Core 2.2 一切正常。使用 .NET Core 3.1,每次启动应用程序时都会收到此警告:

'AddEntityFramework*' was called on the service provider, but 'UseInternalServiceProvider' wasn't called in the DbContext options configuration. Remove the 'AddEntityFramework*' call as in most cases it's not needed and might cause conflicts with other products and services registered in the same service provider.

查找 UseInternalServiceProvider 方法,看起来应该在 options 上调用以传递主要服务提供者。不幸的是,此时服务提供者还不存在。即将建成。

我不明白问题是什么,这个警告想告诉我什么,但没能做到。我怎样才能让这个警告消失?网络还不知道此消息。

删除AddEntityFrameworkNpgsqldocs explain 即:

Calling this method is no longer necessary when building most applications, including those that use dependency injection in ASP.NET or elsewhere. It is only needed when building the internal service provider for use with the method. This is not recommend other than for some advanced scenarios.

Npgsql 的实际 Getting Started 页面显示不需要任何额外的东西:

simply place the following in your ConfigureServices method in Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    // Other DI initializations

    services.AddDbContext<BloggingContext>(options =>
            options.UseNpgsql(Configuration.GetConnectionString("BloggingContext")));
}