private static ExpandedProjectionNode ApplyProjectionForProperty(ExpandedProjectionNode parentNode, string propertyName, ResourceProperty property, ResourceType targetResourceType, bool lastPathSegment) { if (property != null) { switch (property.TypeKind) { case ResourceTypeKind.ComplexType: if (!lastPathSegment) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_ComplexPropertyAsInnerSelectSegment(targetResourceType.FullName, propertyName)); } break; case ResourceTypeKind.Primitive: if (!lastPathSegment) { if (property.IsOfKind(ResourcePropertyKind.Stream)) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_NamedStreamMustBeLastSegmentInSelect(propertyName)); } throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_PrimitivePropertyUsedAsNavigationProperty(targetResourceType.FullName, propertyName)); } break; case ResourceTypeKind.Collection: if (!lastPathSegment) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_CollectionPropertyAsInnerSelectSegment(targetResourceType.FullName, propertyName)); } break; } } ExpandedProjectionNode node = parentNode.AddProjectionNode(propertyName, property, targetResourceType, lastPathSegment); if (lastPathSegment && (node != null)) { node.ProjectionFound = true; node.MarkSubtreeAsProjected(); } return(node); }