.NET Core中的IServiceCollection中不提供UseNpgsql [英] UseNpgsql not available in IServiceCollection in .NET Core

查看:423
本文介绍了.NET Core中的IServiceCollection中不提供UseNpgsql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2017中具有.NET Core项目。我试图添加(Postgresql)数据库连接。这是一个代码:

I have .NET Core project in Visual Studio 2017. I am trying to add (Postgresql) database connection. Here is a code:

public void ConfigureServices(IServiceCollection services)
{
     services.AddMvc();

     services.AddDbContext<ConexionWebApi>(options => {
     options.UseNpgsql("ConnectionString", b => b.MigrationsAssembly("WebAPISample"));
     });

}

但是useNpgsql会产生以下错误:

But useNpgsql generates the following error:


'DbContextOptionsBuilder'不包含'UseNpgsql'的定义,并且找不到扩展方法'UseNpgsl'接受类型为'DbContextOptionsBuilder'的第一个参数(您错过了using指令还是汇编引用?)

'DbContextOptionsBuilder' does not contain a definition for 'UseNpgsql' and no extension method 'UseNpgsl' accepting a first argument of type 'DbContextOptionsBuilder' could be found (are you missing a using directive or an assembly refence?)

我安装了以下NuGet软件包:

I installed the followings NuGet packages:

Microsoft.EntityFrameworkCore.Tools,    
Npgsql.EntityFrameworkCore.PostgreSQL,  
Npgsql.EntityFrameworkCore.PostgreSQL.Design.

我应该安装其他库吗?

推荐答案

我遇到了同样的问题。我通过使用Microsoft.EntityFrameworkCore添加

I had the same issue. I resolved it by adding

using Microsoft.EntityFrameworkCore;

这篇关于.NET Core中的IServiceCollection中不提供UseNpgsql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆