缺少SqlConnection的程序集引用

时间:2016-04-18 04:27:31

标签: dapper sqlclient

我还是MVC和dapper ORM的新手。 假设我使用dapper进行MVC,当我尝试构建解决方案时,它显示消息: ' SqlConnection不包含'查询'的定义。没有扩展方法'查询'接受类型' SqlConnection'。

的第一个参数

这是代码:

using System.Collections.Generic;
using System.Data.SqlClient;



  public string Connectionstring = @"Data Source = KL - PT - 049\sqlexpress;Initial Catalog = Record; Integrated Security = True";

    public IEnumerable<Customer> GetCustomers()
    {
        using (SqlConnection conn = new SqlConnection(Connectionstring))

        {

            conn.Open();
            var customer = conn.**Query**<Customer>("Select * from Customer");
            return customer;
        }

我的问题是:如果我使用这种方式,上面的查询是否应该没问题?既然我已经使用了data.sqlClient引用?

1 个答案:

答案 0 :(得分:1)

添加

using Dapper;

位于文件顶部。

注意:在Visual Studio的最新版本中,您还可以在未解析的扩展方法上按 ctrl + ,它将为您提供修复:

enter image description here