/// <summary> /// Query a SELECT statement which returns results /// </summary> /// <param name="query"></param> /// <param name="result"></param> /// <returns></returns> protected CollectionValue Read(ICompiledQuery query, CollectionValue result) { if (this.Connection != null && this.Connection.State == ConnectionState.Open) { using (IDbCommand command = this.Connection.CreateCommand()) { command.CommandText = query.Compiled.FirstOrDefault(); using (IDataReader reader = command.ExecuteReader()) { if (reader != null) { while (reader.Read() == true) { DocumentValue row = new DocumentValue(); for (int field = 0; field < reader.FieldCount; field++) { row.Set(reader.GetName(field), reader.GetValue(field)); } result.Add(row); } } } } } return result; }
/// <summary> /// Converts a BsonDocument to a DocumentValue (known to Potato) /// </summary> /// <param name="document"></param> /// <returns></returns> protected DocumentValue ToDocument(BsonDocument document) { DocumentValue row = new DocumentValue(); foreach (BsonElement value in document.Elements) { var dotNetValue = BsonTypeMapper.MapToDotNetValue(value.Value); if (dotNetValue is ObjectId) { dotNetValue = dotNetValue.ToString(); } row.Set(value.Name, dotNetValue); } return row; }