I'm trying to parse query results returned from an Azure Elastic Scale MultiShardConnection. It doesn't look like it inherits from SqlConnection or DbConnection so the Dapper methods are not available. This make sense when you consider that it's executing a fan-out query that is union'ed together. What I was hoping to do was to use existing Dapper functionality to just handle the parser of the reader results to a type.
Are those mapping features available if I don't use Dapper for the original connection?
Below are the types I'm working with:
MultiShardConnection : IDisposable
MultiShardCommand : DbCommand
MultiShardDataReader : DbDataReader, IDataReader, IDisposable, IDataRecord
Here's an example query where I'm trying to use the Dapper mapper.
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;
Update
I ended up needing to use 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();
}