public static IList <FastExpando> QuerySql(this IDbConnection connection, string sql, IDictionary <string, object> parameters) { var cmd = connection.CreateCommand(); cmd.CommandText = sql; cmd.CommandType = CommandType.Text; CreateParameters(parameters, cmd); var results = new List <FastExpando>(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var expando = new FastExpando(); var dict = (IDictionary <string, object>)expando; for (int i = 0; i < reader.FieldCount; i++) { object value = reader.GetValue(i); if (value == DBNull.Value) { value = null; } dict[reader.GetName(i)] = value; } results.Add(expando); } } return(results); }
/// <summary> /// Copies the FastExpando while mapping the fields given the map. /// </summary> /// <param name="map">The map of input fields to output fields.</param> /// <returns>A modified copy of the expando.</returns> public FastExpando Transform(IDictionary <string, string> map) { FastExpando other = new FastExpando(); foreach (var pair in data) { other.data.Add(pair.Key, pair.Value); } // mutate the results other.Mutate(map); return(other); }