public string TranslateSelectExpandClause(SelectExpandClause selectExpandClause, bool firstFlag) { ExceptionUtils.CheckArgumentNotNull(selectExpandClause, "selectExpandClause"); List <string> selectList = selectExpandClause.GetCurrentLevelSelectList(); string selectClause = null; if (selectList.Any()) { selectClause = String.Join(ODataConstants.ContextUriProjectionPropertySeparator, selectList.ToArray()); } selectClause = string.IsNullOrEmpty(selectClause) ? null : string.Concat("$select", ExpressionConstants.SymbolEqual, isFirstSelectItem ? Uri.EscapeDataString(selectClause) : selectClause); isFirstSelectItem = false; string expandClause = null; foreach (ExpandedNavigationSelectItem expandSelectItem in selectExpandClause.SelectedItems.OfType <ExpandedNavigationSelectItem>()) { if (string.IsNullOrEmpty(expandClause)) { expandClause = firstFlag ? expandClause : string.Concat("$expand", ExpressionConstants.SymbolEqual); } else { expandClause += ExpressionConstants.SymbolComma; } expandClause += this.Translate(expandSelectItem); } if (string.IsNullOrEmpty(expandClause)) { return(selectClause); } else { if (firstFlag) { return(string.IsNullOrEmpty(selectClause) ? string.Concat("$expand=", Uri.EscapeDataString(expandClause)) : string.Concat(selectClause, "&$expand=", Uri.EscapeDataString(expandClause))); } else { return(string.IsNullOrEmpty(selectClause) ? expandClause : string.Concat(selectClause, ";" + expandClause)); } } }
/// <summary> /// Build the expand clause for a given level in the selectExpandClause /// </summary> /// <param name="selectExpandClause">the current level select expand clause</param> /// <param name="firstFlag">whether is inner SelectExpandClause</param> /// <returns>the select and expand segment for context url in this level.</returns> public string TranslateSelectExpandClause(SelectExpandClause selectExpandClause, bool firstFlag) { ExceptionUtils.CheckArgumentNotNull(selectExpandClause, "selectExpandClause"); List <string> selectList = selectExpandClause.GetCurrentLevelSelectList(); string selectClause = null; string expandClause = null; if (selectList.Any()) { selectClause = String.Join(ODataConstants.ContextUriProjectionPropertySeparator, selectList.ToArray()); } foreach (SelectItem selectItem in selectExpandClause.SelectedItems) { if (selectItem is PathSelectItem pathSelectItem) { selectClause += this.Translate(pathSelectItem); } else if (selectItem.GetType() == typeof(ExpandedNavigationSelectItem)) { if (string.IsNullOrEmpty(expandClause)) { expandClause = firstFlag ? expandClause : string.Concat(ExpressionConstants.QueryOptionExpand, ExpressionConstants.SymbolEqual); } else { expandClause += ExpressionConstants.SymbolComma; } expandClause += this.Translate((ExpandedNavigationSelectItem)selectItem); } else if (selectItem.GetType() == typeof(ExpandedReferenceSelectItem)) { if (string.IsNullOrEmpty(expandClause)) { expandClause = firstFlag ? expandClause : string.Concat(ExpressionConstants.QueryOptionExpand, ExpressionConstants.SymbolEqual); } else { expandClause += ExpressionConstants.SymbolComma; } expandClause += this.Translate((ExpandedReferenceSelectItem)selectItem) + ODataConstants.UriSegmentSeparator + ODataConstants.EntityReferenceSegmentName; } } selectClause = string.IsNullOrEmpty(selectClause) ? null : string.Concat(ExpressionConstants.QueryOptionSelect, ExpressionConstants.SymbolEqual, firstFlag ? Uri.EscapeDataString(selectClause) : selectClause); if (string.IsNullOrEmpty(expandClause)) { return(selectClause); } else { if (firstFlag) { return(string.IsNullOrEmpty(selectClause) ? string.Concat(ExpressionConstants.QueryOptionExpand, ExpressionConstants.SymbolEqual, Uri.EscapeDataString(expandClause)) : string.Concat(selectClause, ExpressionConstants.SymbolQueryConcatenate, ExpressionConstants.QueryOptionExpand, ExpressionConstants.SymbolEqual, Uri.EscapeDataString(expandClause))); } else { return(string.IsNullOrEmpty(selectClause) ? expandClause : string.Concat(selectClause, ";" + expandClause)); } } }