我正在将 ASP.NET Core 应用程序从 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
上调用传递主要服务提供者。不幸的是,此时服务提供者还不存在。它即将建成。我不明白问题是什么以及这个警告想告诉我什么,但没能做到。我怎样才能让那个警告消失?网络还不知道这条消息。
最佳答案
删除 AddEntityFrameworkNpgsql
. docs 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.
实际Getting Started页面对于 Npgsql 显示不需要任何额外的东西:
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")));
}
关于c# - 在 DbContext 选项配置中未调用“AddEntityFramework *' was called on the service provider, but ' UseInternalServiceProvider”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62917136/