示例#1
0
        private string GetAutoSelectRawValue()
        {
            var            selectRawValue     = RawValues.Select;
            var            autoSelectRawValue = String.Empty;
            IEdmEntityType baseEntityType     = Context.TargetStructuredType as IEdmEntityType;

            if (String.IsNullOrEmpty(selectRawValue))
            {
                var autoSelectProperties = EdmLibHelpers.GetAutoSelectProperties(Context.TargetProperty,
                                                                                 Context.TargetStructuredType, Context.Model);

                foreach (var property in autoSelectProperties)
                {
                    if (!String.IsNullOrEmpty(autoSelectRawValue))
                    {
                        autoSelectRawValue += ",";
                    }

                    if (baseEntityType != null && property.DeclaringType != baseEntityType)
                    {
                        autoSelectRawValue += String.Format(CultureInfo.InvariantCulture, "{0}/",
                                                            property.DeclaringType.FullTypeName());
                    }

                    autoSelectRawValue += property.Name;
                }

                if (!String.IsNullOrEmpty(autoSelectRawValue))
                {
                    if (!String.IsNullOrEmpty(selectRawValue))
                    {
                        selectRawValue = String.Format(CultureInfo.InvariantCulture, "{0},{1}",
                                                       autoSelectRawValue, selectRawValue);
                    }
                    else
                    {
                        selectRawValue = autoSelectRawValue;
                    }
                }
            }

            return(selectRawValue);
        }
示例#2
0
        private void GetAutoSelectExpandItems(
            IEdmEntityType baseEntityType,
            IEdmModel model,
            IEdmNavigationSource navigationSource,
            bool isAllSelected,
            ModelBoundQuerySettings modelBoundQuerySettings,
            int depth,
            out List <SelectItem> autoSelectItems,
            out List <SelectItem> autoExpandItems)
        {
            autoSelectItems = new List <SelectItem>();
            var autoSelectProperties = EdmLibHelpers.GetAutoSelectProperties(null,
                                                                             baseEntityType, model, modelBoundQuerySettings);

            foreach (var autoSelectProperty in autoSelectProperties)
            {
                List <ODataPathSegment> pathSegments = new List <ODataPathSegment>()
                {
                    new PropertySegment(autoSelectProperty)
                };

                PathSelectItem pathSelectItem = new PathSelectItem(
                    new ODataSelectPath(pathSegments));
                autoSelectItems.Add(pathSelectItem);
            }

            autoExpandItems = new List <SelectItem>();
            depth--;
            if (depth < 0)
            {
                return;
            }

            var autoExpandNavigationProperties = EdmLibHelpers.GetAutoExpandNavigationProperties(null, baseEntityType,
                                                                                                 model, !isAllSelected, modelBoundQuerySettings);

            foreach (var navigationProperty in autoExpandNavigationProperties)
            {
                IEdmNavigationSource currentEdmNavigationSource =
                    navigationSource.FindNavigationTarget(navigationProperty);

                if (currentEdmNavigationSource != null)
                {
                    List <ODataPathSegment> pathSegments = new List <ODataPathSegment>()
                    {
                        new NavigationPropertySegment(navigationProperty, currentEdmNavigationSource)
                    };

                    ODataExpandPath    expandPath         = new ODataExpandPath(pathSegments);
                    SelectExpandClause selectExpandClause = new SelectExpandClause(new List <SelectItem>(),
                                                                                   true);
                    ExpandedNavigationSelectItem item = new ExpandedNavigationSelectItem(expandPath,
                                                                                         currentEdmNavigationSource, selectExpandClause);
                    modelBoundQuerySettings = EdmLibHelpers.GetModelBoundQuerySettings(navigationProperty,
                                                                                       navigationProperty.ToEntityType(), model);
                    List <SelectItem> nestedSelectItems;
                    List <SelectItem> nestedExpandItems;

                    int maxExpandDepth = GetMaxExpandDepth(modelBoundQuerySettings, navigationProperty.Name);
                    if (maxExpandDepth != 0 && maxExpandDepth < depth)
                    {
                        depth = maxExpandDepth;
                    }

                    GetAutoSelectExpandItems(
                        currentEdmNavigationSource.EntityType(),
                        model,
                        item.NavigationSource,
                        true,
                        modelBoundQuerySettings,
                        depth,
                        out nestedSelectItems,
                        out nestedExpandItems);

                    selectExpandClause = new SelectExpandClause(nestedSelectItems.Concat(nestedExpandItems),
                                                                nestedSelectItems.Count == 0);
                    item = new ExpandedNavigationSelectItem(expandPath, currentEdmNavigationSource,
                                                            selectExpandClause);

                    autoExpandItems.Add(item);
                    if (!isAllSelected || autoSelectProperties.Count() != 0)
                    {
                        PathSelectItem pathSelectItem = new PathSelectItem(
                            new ODataSelectPath(pathSegments));
                        autoExpandItems.Add(pathSelectItem);
                    }
                }
            }
        }
示例#3
0
        private string GetAutoSelectRawValue()
        {
            var            selectRawValue     = RawValues.Select;
            var            autoSelectRawValue = String.Empty;
            IEdmEntityType baseEntityType     = Context.TargetStructuredType as IEdmEntityType;

            if (String.IsNullOrEmpty(selectRawValue))
            {
                var autoSelectProperties = EdmLibHelpers.GetAutoSelectProperties(Context.TargetProperty,
                                                                                 Context.TargetStructuredType, Context.Model);

                foreach (var property in autoSelectProperties)
                {
                    if (!String.IsNullOrEmpty(autoSelectRawValue))
                    {
                        autoSelectRawValue += ",";
                    }

                    if (baseEntityType != null && property.DeclaringType != baseEntityType)
                    {
                        autoSelectRawValue += String.Format(CultureInfo.InvariantCulture, "{0}/",
                                                            property.DeclaringType.FullTypeName());
                    }

                    autoSelectRawValue += property.Name;
                }

                if (!String.IsNullOrEmpty(autoSelectRawValue))
                {
                    // Add dynamic fields generated in $compute and $apply
                    if (Compute != null)
                    {
                        string computeAliases = string.Join(",", Compute.ComputeClause.ComputedItems.Select(c => c.Alias));

                        if (!String.IsNullOrEmpty(computeAliases))
                        {
                            autoSelectRawValue = String.Format(CultureInfo.InvariantCulture, "{0},{1}",
                                                               autoSelectRawValue, computeAliases);
                        }
                    }

                    if (Apply != null)
                    {
                        string computeAliases = string.Join(",", Apply.ApplyClause.Transformations.OfType <ComputeTransformationNode>().SelectMany(c => c.Expressions).Select(c => c.Alias));

                        if (!String.IsNullOrEmpty(computeAliases))
                        {
                            autoSelectRawValue = String.Format(CultureInfo.InvariantCulture, "{0},{1}",
                                                               autoSelectRawValue, computeAliases);
                        }
                    }

                    if (!String.IsNullOrEmpty(selectRawValue))
                    {
                        selectRawValue = String.Format(CultureInfo.InvariantCulture, "{0},{1}",
                                                       autoSelectRawValue, selectRawValue);
                    }
                    else
                    {
                        selectRawValue = autoSelectRawValue;
                    }
                }
            }

            return(selectRawValue);
        }