[英]Why is there an ambiguity with Dapper QueryAsync when used with MiniProfiler?
EDIT 1 : When trying to call the extension method explicitly:编辑1 :尝试显式调用扩展方法时:
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'
类型 'SqlMapper' 存在于 'Dapper.StrongName, Version=1.50.2.0, Culture=neutral, PublicKeyToken=e3e8412083d25dd3' 和 '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) Dapper.StrongName 是 MiniProfiler(.Net 标准 1.5)的依赖项
I'm trying to use MiniProfiler alongside Dapper to see SQL commands send to the backend.我正在尝试将 MiniProfiler 与 Dapper 一起使用来查看发送到后端的 SQL 命令。
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?)'
以下方法或属性之间的调用不明确:'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?)'
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 存储提供程序的依赖项安装的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.