找不到类型或命名空间名称“IDbConnection”

时间:2017-03-30 22:16:08

标签: c# .net postgresql asp.net-web-api dapper

使用Dapper设置.Net core web api时遇到问题。似乎我已经在dappperApi.csproj文件中包含了Dapper,但由于某种原因,为了连接到PostgreSQL,我不需要“IDbConnection”和“SqlConnection”类型。我有以下错误:“无法找到类型或命名空间名称'IDbConnection'(您是否缺少using指令或程序集引用?)[dapperApi] 。”这是ApplicantRepository文件:

using System.Collections.Generic;
using System.Linq;
using Dapper;

public class ApplicantRepository : IApplicantRepository {
   private string connectionString;
   private IDbConnection _db;

   public ApplicantRepository() {
       connectionString = @"User ID=MyName;Password=MyPassword;Host=localhost;Port=5432;Database=test_db;Pooling=true;";
    _db = new SqlConnection(connectionString);
   }

   public bool AddApplicant(Applicant newApplicant) {
      int rowsAffected = this._db.Execute(@"INSERT Applicant([id], [name]) values (@id, @name)", new {id=newApplicant.id, name=newApplicant.name});

      if (rowsAffected > 0)
        return true;
      else
        return false;
      return true;
   }
}

这是我的dopperApi.csproj文件:

<Project Sdk="Microsoft.NET.Sdk.Web">

   <PropertyGroup>
     <TargetFramework>netcoreapp1.1</TargetFramework>
   </PropertyGroup>

   <ItemGroup>
     <Folder Include="wwwroot\" />
   </ItemGroup>

   <ItemGroup>
     <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
     <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
     <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
     <PackageReference Include="Dapper" Version="1.50.2" />
   </ItemGroup>

</Project>

我不确定我做错了什么。我是.net核心和dappler的新手。我没有visual studio,这就是我将Dapper作为包参考包含的原因。 提前谢谢!

0 个答案:

没有答案