我正在尝试解析从 Azure Elastic Scale MultiShardConnection 返回的查询结果。它看起来不像是从 SqlConnection 或 DbConnection 继承的,因此 Dapper 方法不可用。当您认为它正在执行联合在一起的扇出查询时,这是有道理的。我希望做的是使用现有的 Dapper 功能将读取器结果解析为类型。
如果我不使用 Dapper 进行原始连接,这些映射功能是否可用?
以下是我正在使用的类型:
MultiShardConnection : IDisposable
MultiShardCommand : DbCommand
MultiShardDataReader : DbDataReader, IDataReader, IDisposable, IDataRecord
这是我尝试使用 Dapper 映射器的示例查询。
Customer customer = null;
using (MultiShardConnection conn = GetMultiShardConnection())
using (MultiShardCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT * FROM [Customer] WHERE ...";
cmd.CommandTimeout = 120;
cmd.CommandTimeoutPerShard = 120;
using (MultiShardDataReader reader = await cmd.ExecuteReaderAsync())
{
while (reader.Read())
{
// Replace this with mapper...
customer = new Customer()
{
CustomerId = reader.GetInt32(0)
//etc...
};
}
}
}
return customer;
更新
我最终需要使用sp_execute_fanout
using (var con = GetConnection())
{
await con.OpenAsync();
return (await con.QueryAsync<Customer>("sp_execute_fanout ", new
{
shard_map_manager_server = "my_server.database.windows.net",
shard_map_manager_database = "my_shardmapmananger",
user_id = "my_username",
password = "my_password",
shard_map_name = "my_shardmap",
statement = "SELECT * FROM Customer"
}, commandTimeout: 120, commandType: CommandType.StoredProcedure)).FirstOrDefault();
}