private void CheckExpandPaths() { if (this.expandPathsAsText.Count > 0) { if (this.queryExpression == null) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_QueryExpandOptionNotApplicable); } if (this.description.TargetResourceType.ResourceTypeKind == ResourceTypeKind.Collection) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_QueryExpandOptionNotApplicable); } } this.expandPaths = new List <ExpandSegmentCollection>(this.expandPathsAsText.Count); for (int i = this.expandPathsAsText.Count - 1; i >= 0; i--) { ExpandSegmentCollection item = this.CheckSingleExpandPath(this.expandPathsAsText[i]); if (item == null) { this.expandPathsAsText.RemoveAt(i); } else { this.expandPaths.Add(item); ExpandedProjectionNode rootProjectionNode = this.GetRootProjectionNode(); for (int j = 0; j < item.Count; j++) { ExpandSegment segment = item[j]; ExpandedProjectionNode node2 = rootProjectionNode.AddExpandedNode(segment); this.GetRootProjectionNode().ExpansionOnDerivedTypesSpecified |= rootProjectionNode.HasExpandedPropertyOnDerivedType; rootProjectionNode = node2; } this.GetRootProjectionNode().ExpansionsSpecified = true; } } }
private ExpandSegmentCollection CheckSingleExpandPath(List <string> path) { ResourceType targetResourceType = this.description.TargetResourceType; ResourceSetWrapper targetContainer = this.description.LastSegmentInfo.TargetContainer; ExpandSegmentCollection segments = new ExpandSegmentCollection(path.Count); bool flag = false; bool previousSegmentIsTypeSegment = false; for (int i = 0; i < path.Count; i++) { string propertyName = path[i]; ResourcePropertyKind stream = ResourcePropertyKind.Stream; ResourceProperty navigationProperty = targetResourceType.TryResolvePropertyName(propertyName, stream); if (navigationProperty == null) { ResourceType type2 = WebUtil.ResolveTypeIdentifier(this.service.Provider, propertyName, targetResourceType, previousSegmentIsTypeSegment); if (type2 == null) { if (targetResourceType.IsOpenType) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.OpenNavigationPropertiesNotSupportedOnOpenTypes(propertyName)); } throw DataServiceException.CreateSyntaxError(System.Data.Services.Strings.RequestUriProcessor_PropertyNotFound(targetResourceType.FullName, propertyName)); } this.description.VerifyProtocolVersion(RequestDescription.Version3Dot0, this.service); targetResourceType = type2; previousSegmentIsTypeSegment = true; } else { previousSegmentIsTypeSegment = false; if (navigationProperty.TypeKind == ResourceTypeKind.EntityType) { targetContainer = this.service.Provider.GetContainer(targetContainer, targetResourceType, navigationProperty); if (targetContainer == null) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.BadRequest_InvalidPropertyNameSpecified(navigationProperty.Name, targetResourceType.FullName)); } bool singleResult = navigationProperty.Kind == ResourcePropertyKind.ResourceReference; DataServiceConfiguration.CheckResourceRightsForRead(targetContainer, singleResult); Expression filter = DataServiceConfiguration.ComposeQueryInterceptors(this.service, targetContainer); if (((targetContainer.PageSize != 0) && !singleResult) && !this.IsCustomPaged) { OrderingInfo orderingInfo = new OrderingInfo(true); ParameterExpression expression = Expression.Parameter(targetContainer.ResourceType.InstanceType, "p"); foreach (ResourceProperty property2 in targetContainer.GetKeyPropertiesForOrderBy()) { Expression expression3; if (property2.CanReflectOnInstanceTypeProperty) { expression3 = Expression.Property(expression, targetContainer.ResourceType.GetPropertyInfo(property2)); } else { expression3 = Expression.Convert(Expression.Call(null, DataServiceProviderMethods.GetValueMethodInfo, expression, Expression.Constant(property2)), property2.Type); } orderingInfo.Add(new OrderingExpression(Expression.Lambda(expression3, new ParameterExpression[] { expression }), true)); } segments.Add(new ExpandSegment(navigationProperty.Name, filter, targetContainer.PageSize, targetContainer, targetResourceType, navigationProperty, orderingInfo)); this.description.VerifyProtocolVersion(RequestDescription.Version2Dot0, this.service); this.description.VerifyAndRaiseResponseVersion(RequestDescription.Version2Dot0, this.service); } else { if (!singleResult && this.IsCustomPaged) { this.CheckAndApplyCustomPaging(null); } segments.Add(new ExpandSegment(navigationProperty.Name, filter, this.service.Configuration.MaxResultsPerCollection, targetContainer, targetResourceType, navigationProperty, null)); } this.description.UpdateAndCheckEpmFeatureVersion(targetContainer, this.service); this.description.UpdateVersions(this.service.OperationContext.Host.RequestAccept, targetContainer, this.service); flag = false; targetResourceType = navigationProperty.ResourceType; } else { flag = true; } } } if (previousSegmentIsTypeSegment) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_QueryParametersPathCannotEndInTypeIdentifier("$expand", targetResourceType.FullName)); } if (!flag) { return(segments); } return(null); }