Why Dapper return an assembly reference is missing for SqlConnection?

dapper sqlclient

Question

I'm still new to MVC and dapper ORM. Suppose I use dapper for MVC and and when I try to build solution, it showing message: 'SqlConnection does not contain a definition for'Query' and no extension method 'Query' accepting a first argument of type 'SqlConnection'.

here is the code:

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

my question is: does the Query above should be fine if I use that way? since I already use data.sqlClient reference?

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

Expert Answer

Add

using Dapper;

at the top of the file.

Note: in recent versions of Visual Studio you can also just press ctrl+. on the unresolved extension method and it will offer to fix it for you:

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