Visual Studio not resolving Dapper.Extension Namespace

2.8k views Asked by At

I am trying to learn how to use Dapper.Extension but after multiple attempts installing and reinstalling the nuget package. I can't get the namespace to resolve and usable. I am creating a generic repository but when i attempt to include the namespace, VS doesn't even see it. I have looked all over their documentation and install guides but can't see anyone else having this issue. Is there something stupid i am over looking? See my Find method below using the extension.

    public T Find(int id)
    {
        using(var conn = _ConnectionFactory.GetConnection())
        {
            return conn.Get<T>(id);
        }
    }
4

There are 4 answers

1
Void Ray On

To test I used VS 2015:

  1. Create new console application
  2. Install-Package DapperExtensions
  3. Install latest version of Dapper: Install-Package Dapper -version 1.50.2

Here is the test code:

using System.Data.SqlClient;
using DapperExtensions;
namespace ConsoleApplication2
{
    public class Foo
    {
        public int Id { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var result = Find(1);
        }
        public static Foo Find(int id)
        {
            using (var conn = new SqlConnection(@"Data Source=.\sqlexpress;Integrated Security=true; Initial Catalog=foo"))
            {
                conn.Open();
                var foo = conn.Get<Foo>(id);
                return foo;
            }
        }
    }
}
0
G Davison On

You have added the libraries correctly but you need to add using references at the top of your classes to import the dapper namespace and add the additional methods to the SqlConnection object. To do so add both of the lines below to the top of your class files, before any namespace declarations.

using Dapper;
using DapperExtensions;

The equivalent in VB.NET would be:

Imports Dapper
Imports DapperExtensions
0
Chet On

I had a similar issue but that was because I had installed "Dapper.Extension" via nuget instead of installing "DapperExtensions". Could you have done something similar?

0
Brikesh Kumar On

There are two nuget packages "DapperExtensions" and "Dapper.Extensions". Make sure you have installed the first one. I did this mistake too