我正在将Dapper作为ORM解决方案进行测试,但遇到了一些扩展方法的问题,比如Execute
或QueryMultiple
:
using (SQLiteConnection con = new SQLiteConnection(GetConnectionString()))
{
con.Open();
string sql = @"
select * from Customer where Id = @id;
select * from Address where CustomerId = @id;";
// QueryMultiple extension ambiguous?
using (var multi = con.QueryMultiple(sql, new { id = 1 }))
{
Customer customer = multi.Read<Customer>().Single();
Address address = multi.Read<Address>().Single();
}
con.Close();
}
我遇到了错误:
在以下方法或属性之间的调用不明确: 'Dapper.SqlMapper.QueryMultiple(System.Data.IDbConnection, string, object, System.Data.IDbTransaction, int?, System.Data.CommandType?)' 和 'Dapper.SqlMapper.QueryMultiple(System.Data.IDbConnection, string, dynamic, System.Data.IDbTransaction, int?, System.Data.CommandType?)'
我不知道如何正确解决这个问题。Dapper的示例中没有提及这样的问题,只是简单地使用了 QueryMultiple
。我能够通过以下方式绕过歧义:
var multi = con.QueryMultiple(new CommandDefinition(sql, new { id = 1 }))
但这真的必要吗?有更好的方法吗?
QueryMultiple
重载方法:IDbConnection cnn, string sql, dynamic param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null
。 - Tim Schmelterdynamic
指定重载..至少就我尝试而言,我在尝试创建这样的重载时会得到编译错误。 - RobSqlMapper
文件吗?在整个项目中搜索QueryMultiple
。也许是旧版本。 - Tim Schmelterdynamic
重载:https://github.com/StackExchange/dapper-dot-net/commit/b87d958314b1a85f52c7ef37b78d3740154b4d04 - Rob