private void RunQuery() { IMongoQuery mongoQuery = _mongoQueryFactory.BuildQuery(); IEnumerable documents = null; try { documents = mongoQuery.RunQuery(Server, Database, Port, Query); Headers.Clear(); Items.Clear(); foreach (IDictionary document in documents) { ItemViewModel model = new ItemViewModel(Headers); foreach (string key in document.Keys) { string k = key; if (Headers.SingleOrDefault(field => field.FieldName == k) == null) { Headers.Add(new FieldViewModel() { FieldName = key }); } model.Data[key] = document[key].ToString(); } Items.Add(model); } NumberOfResults = string.Format("{0}: {1} docs", DateTime.Now.ToString("HH:mm:ss"), Items.Count); ListViewExtension.RefreshUI(Headers); } catch (QueryValidationException ex) { _userMessageService.ShowMessage(ex.Message); return; } catch (UnknownServerException ex) { _userMessageService.ShowMessage(ex.Message); return; } catch (Exception ex) { _userMessageService.ShowMessage("An error occurred while executing the query: " + ex); return; } finally { mongoQuery.Dispose(); } }