我们使用DapperWrapper类来扩展和包装Dapper IDbConnection接口,以支持测试我们的存储库层.但是,在尝试使用Dapper中的父/子映射支持将查询中的多个结果集映射回分层对象时,我们遇到了一个问题,如此处的ParentChildIdentityAssociations示例测试中所示:
https://github.com/SamSaffron/dapper-dot-net/blob/master/Tests/Tests.cs#L1443
所以Dapper支持这个功能,但是当我们在DapperWrapper中使用IDbExecutor时,似乎会丢失对多个类型参数的支持.当我尝试执行以下操作时,出现编译错误"类型参数数量不正确".
var results = Db.Query<Deal, DealOption, Deal>(template.RawSql, template.Parameters).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
来自DapperWrapper的以下示例说明了我们实际调用的方法以及随附的SqlConnection对象(使用Dapper扩展).原始SqlConnection/IDbConnection对象是否支持由T定义的多个类型参数是有原因的,而以相同方式定义的包装方法不会?
public IEnumerable<T> Query<T>(
string sql,
object param = null,
IDbTransaction transaction = null,
bool buffered = true,
int? commandTimeout = default(int?),
CommandType? commandType = default(CommandType?))
{
return _sqlConnection.Query<T>(
sql,
param,
transaction,
buffered,
commandTimeout,
commandType);
}
Run Code Online (Sandbox Code Playgroud)