简体   繁体   中英

Why is there an ambiguity with Dapper QueryAsync when used with MiniProfiler?

EDIT 1 : When trying to call the extension method explicitly:

Dapper.SqlMapper.QueryAsync<dynamic>(cnx, "SELECT TOP 10 * FROM dbo.Company;");

I have a much more explicit error message:

The type 'SqlMapper' exists in both 'Dapper.StrongName, Version=1.50.2.0, Culture=neutral, PublicKeyToken=e3e8412083d25dd3' and 'Dapper, Version=1.50.5.0, Culture=neutral, PublicKeyToken=null'

Can I do something about it ?

Dapper.StrongName is a dependency of MiniProfiler (.Net standard 1.5)


I'm trying to use MiniProfiler alongside Dapper to see SQL commands send to the backend.

I have the following code to produce an instrumented connection on demand:

   private static DbConnection GetCnx(bool instrumented = false)
    {
        var cnx = new SqlConnection("Data Source=foo;Initial Catalog=bar;Integrated Security=SSPI;");
        // Enabling statistics for logging purposes
        if (instrumented)
            return new ProfiledDbConnection(cnx, MiniProfiler.Current);
        else
            return cnx;
    }

The following consuming code won't compile anymore:

using (DbConnection cnx = GetCnx())
{
      await cnx.OpenAsync();
      return await cnx.QueryAsync<dynamic>("SELECT TOP 10 * FROM dbo.Company;");
}

The call is ambiguous between the following methods or properties: 'Dapper.SqlMapper.QueryAsync(System.Data.IDbConnection, string, object, System.Data.IDbTransaction, int?, System.Data.CommandType?)' and 'Dapper.SqlMapper.QueryAsync(System.Data.IDbConnection, string, object, System.Data.IDbTransaction, int?, System.Data.CommandType?)'

The ambiguous methods are identical, unless I need a new pair of glass.

What am I missing here ?

解决方案是使用 Dapper.StrongName nuget 而不是 Dapper。

还可以删除现有明确包含的对 Dapper 的 nuget 引用,并使用作为 MiniProfiler 存储提供程序的依赖项安装的内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM