Exemple #1
0
        /// <summary>
        /// This function populates the Select and Expand field lists in the class from reading the data from the
        /// Odata URI. <see cref="SelectExpandClause"/>
        /// </summary>
        private void PopulateSelectAndExpandQueryFields(string queryString)
        {
            var pathSelectedItems = ODataUri.SelectAndExpand.SelectedItems;

            foreach (var item in pathSelectedItems)
            {
                switch (item)
                {
                //its a select query
                case PathSelectItem pathSelectItem:
                    SelectFieldList.Add(pathSelectItem.SelectedPath.FirstSegment.Identifier);
                    break;

                //its an expand query
                case ExpandedNavigationSelectItem expandedNavigationSelectItem:
                    //get the string from the start of the navigation source name.
                    ExpandFieldExpression = queryString.Substring(queryString.IndexOf(expandedNavigationSelectItem.NavigationSource.Name, StringComparison.Ordinal));
                    //check if there are other queries present and chunk them off to remain with only the expand parameter
                    var index = ExpandFieldExpression.IndexOf("&", StringComparison.Ordinal);
                    if (index > 0)
                    {
                        ExpandFieldExpression = ExpandFieldExpression.Substring(0, index);
                    }

                    break;
                }
            }
        }
        /// <summary>
        /// This function populates the Select and Expand field lists in the class from reading the data from the
        /// Odata URI. <see cref="SelectExpandClause"/>
        /// </summary>
        protected override void PopulateSelectAndExpandQueryFields(string queryString)
        {
            if (ODataUri.SelectAndExpand == null)
            {
                return;
            }

            var pathSelectedItems = ODataUri.SelectAndExpand.SelectedItems;

            foreach (var item in pathSelectedItems)
            {
                switch (item)
                {
                //its a select query
                case PathSelectItem pathSelectItem:
                    SelectFieldList.Add(pathSelectItem.SelectedPath.FirstSegment.Identifier);
                    break;

                //its an expand query
                case ExpandedNavigationSelectItem expandedNavigationSelectItem:
                    if (!string.IsNullOrEmpty(ExpandFieldExpression))
                    {
                        break;     // multiple expand parameters will result in this case being processed multiple times. So don't do it again if we already did it the first time.
                    }
                    //get the string from the start of the navigation source name.
                    ExpandFieldExpression = queryString.Substring(queryString.IndexOf(expandedNavigationSelectItem.PathToNavigationProperty.First().Identifier, StringComparison.Ordinal));
                    //check if there are other queries present and chunk them off to remain with only the expand parameter
                    var index = ExpandFieldExpression.IndexOf("&", StringComparison.Ordinal);
                    if (index > 0)
                    {
                        ExpandFieldExpression = ExpandFieldExpression.Substring(0, index);
                    }

                    break;
                }
            }
        }