private static IEnumerable <SelectItem> GetAutoExpandedNavigationSelectItems( IEdmEntityType baseEntityType, IEdmModel model, string alreadyExpandedNavigationSourceName, IEdmNavigationSource navigationSource, bool isAllSelected, bool searchDerivedTypeWhenAutoExpand) { var expandItems = new List <SelectItem>(); var autoExpandNavigationProperties = EdmLibHelpers.GetAutoExpandNavigationProperties(baseEntityType, model, searchDerivedTypeWhenAutoExpand); foreach (var navigationProperty in autoExpandNavigationProperties) { if (!alreadyExpandedNavigationSourceName.Equals(navigationProperty.Name)) { IEdmEntityType entityType = navigationProperty.DeclaringEntityType(); 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); if (!currentEdmNavigationSource.EntityType().Equals(entityType)) { IEnumerable <SelectItem> nestedSelectItems = GetAutoExpandedNavigationSelectItems( currentEdmNavigationSource.EntityType(), model, alreadyExpandedNavigationSourceName, item.NavigationSource, true, searchDerivedTypeWhenAutoExpand); selectExpandClause = new SelectExpandClause(nestedSelectItems, true); item = new ExpandedNavigationSelectItem(expandPath, currentEdmNavigationSource, selectExpandClause); } expandItems.Add(item); if (!isAllSelected) { PathSelectItem pathSelectItem = new PathSelectItem( new ODataSelectPath(pathSegments)); expandItems.Add(pathSelectItem); } } } } return(expandItems); }
private string GetAutoExpandRawValue() { var expandRawValue = RawValues.Expand; IEdmEntityType baseEntityType = Context.TargetStructuredType as IEdmEntityType; var autoExpandRawValue = string.Empty; var autoExpandNavigationProperties = EdmLibHelpers.GetAutoExpandNavigationProperties( Context.TargetProperty, Context.TargetStructuredType, Context.Model, !string.IsNullOrEmpty(RawValues.Select)); foreach (var property in autoExpandNavigationProperties) { if (!string.IsNullOrEmpty(autoExpandRawValue)) { autoExpandRawValue += ","; } if (property.DeclaringEntityType() != baseEntityType) { autoExpandRawValue += string.Format( CultureInfo.InvariantCulture, "{0}/", (object)property.DeclaringEntityType().FullTypeName()); } autoExpandRawValue += property.Name; } if (!string.IsNullOrEmpty(autoExpandRawValue)) { if (!string.IsNullOrEmpty(expandRawValue)) { expandRawValue = string.Format(CultureInfo.InvariantCulture, "{0},{1}", autoExpandRawValue, expandRawValue); } else { expandRawValue = autoExpandRawValue; } } return(expandRawValue); }
private string GetAutoExpandRawValue(bool discoverDerivedTypeWhenAutoExpand) { var expandRawValue = RawValues.Expand; IEdmEntityType baseEntityType = Context.ElementType as IEdmEntityType; var autoExpandRawValue = String.Empty; var autoExpandNavigationProperties = EdmLibHelpers.GetAutoExpandNavigationProperties(baseEntityType, Context.Model, discoverDerivedTypeWhenAutoExpand); foreach (var property in autoExpandNavigationProperties) { if (!String.IsNullOrEmpty(autoExpandRawValue)) { autoExpandRawValue += ","; } if (property.DeclaringEntityType() != baseEntityType) { autoExpandRawValue += String.Format(CultureInfo.InvariantCulture, "{0}/", property.DeclaringEntityType().FullTypeName()); } autoExpandRawValue += property.Name; } if (!String.IsNullOrEmpty(autoExpandRawValue)) { if (!String.IsNullOrEmpty(expandRawValue)) { expandRawValue = String.Format(CultureInfo.InvariantCulture, "{0},{1}", autoExpandRawValue, expandRawValue); } else { expandRawValue = autoExpandRawValue; } } return(expandRawValue); }
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); } } } }