/// <summary> /// Выполнение запроса /// </summary> /// <param name="query">Запрос</param> /// <param name="options">Параметры запроса</param> /// <returns>Результирующий <see cref="XElement"/></returns> public XElement ExecuteQuery(string query, DocumentStorageOptions options = null) { if (null == _bSharpContext) return null; XElement result; string ns = null; if (options != null) { if (!string.IsNullOrWhiteSpace(options.Collection)) { ns = options.Collection; } } var selected = _bSharpContext.ResolveAll(query, ns).ToArray(); if (selected.Length == 0) { if (WrapAlways) { result = new XElement(WrapperName); result.SetAttributeValue(IsEmptyResultAttribute, true); } else { result = null; } } else if (selected.Length == 1) { if (WrapAlways) { result = new XElement(WrapperName); result.Add(selected[0].Compiled); } else { result = selected[0].Compiled; } } else { result = new XElement(WrapperName); result.SetAttributeValue(IsComplexResultAttribute, true); foreach (var bSharpClass in selected) { result.Add(bSharpClass.Compiled); } } return result; }
/// <summary> /// Выполнить запрос /// </summary> /// <param name="query"></param> /// <param name="options"></param> /// <returns></returns> public XElement ExecuteQuery(string query, DocumentStorageOptions options = null) { var cursor = Connector.Collection.Find(new QueryDocument(BsonDocument.Parse(query))); if (null != options && null != options.Fields) { cursor = cursor.SetFields(options.Fields); } if (0 != options.Limit) { cursor = cursor.SetLimit(options.Limit); } var result = new XElement("result"); foreach (var doc in cursor) { result.Add(ConvertToXElement(doc,"doc")); } return result; }