Why Dapper return an assembly reference is missing for SqlConnection?

dapper sqlclient

Question

MVC and dapper ORM are still new to me. If I use Dapper for MVC, it can display the following error when I attempt to build the solution: "SqlConnection does not include a definition for'Query' and no extension method 'Query' taking a first parameter of type 'SqlConnection'."

The key is as follows:

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;
        }

Do you think using the Query above in that manner is acceptable? considering that I already use the data.sqlClient reference?

1
1
4/18/2016 4:27:30 AM

Expert Answer

Add

using Dapper;

on the document's top.

Note: Modern versions of Visual Studio allow you to just hitctrl +. it will offer to correct it for you if you click on the unresolved extension method:

enter image description here

1
4/18/2016 10:52:13 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow