【问题标题】:Why is there an ambiguity with Dapper QueryAsync when used with MiniProfiler?为什么与 MiniProfiler 一起使用时,Dapper QueryAsync 会出现歧义?
【发布时间】:2021-05-30 15:06:15
【问题描述】:

编辑1: 尝试显式调用扩展方法时:

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

我有一个更明确的错误消息:

“Dapper.StrongName, Version=1.50.2.0, Culture=neutral, PublicKeyToken=e3e8412083d25dd3”和“Dapper, Version=1.50.5.0, Culture=neutral, PublicKeyToken=null”中都存在“SqlMapper”类型

我能做点什么吗?

Dapper.StrongName 是 MiniProfiler(.Net 标准 1.5)的依赖项


我正在尝试使用 MiniProfiler 和 Dapper 来查看发送到后端的 SQL 命令。

我有以下代码来按需生成检测连接:

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

以下消费代码将不再编译:

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

以下方法或属性之间的调用不明确:'Dapper.SqlMapper.QueryAsync(System.Data.IDbConnection, string, object, System.Data.IDbTransaction, int?, System.Data.CommandType?)' 和 ' Dapper.SqlMapper.QueryAsync(System.Data.IDbConnection, string, object, System.Data.IDbTransaction, int?, System.Data.CommandType?)'

模棱两可的方法是相同的,除非我需要一副新的玻璃。

我在这里错过了什么?

【问题讨论】:

    标签: c# dapper miniprofiler .net-core-2.2


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-31
        • 1970-01-01
        • 1970-01-01
        • 2013-09-13
        • 1970-01-01
        • 2013-04-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多