AddDbContext is not available in IServiceCollection in .NET Core
I have a .NET Core 2 project in Visual Studio 2017. I am trying to add (Postgresql) a database connection. Here is the code:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext(options =>
options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
// Add framework services.
services.AddMvc();
}
But the compiler is complaining about this message:
IServiceCollection does not contain a definition for 'AddDbContext' and no extension method 'AddDbContext' that takes a first argument of type "IServiceCollection" can be found (are you missing a directive or assembly reference?)
I have installed the NgGet NuGet package. I also tried to install the NuGet package EntityFramework, but I get the error:
Failed to restore package. Rollback package changes for "MyProject".
Is this the root of my problem? Should I install any other library?
This question uses AddEntityFramework () and AddEntityFrameworkNpgsql (), but those two are also not recognized by the compiler in my project.
source to share