Beispiel #1
0
        /// <summary>
        /// Binds the given member token.
        /// </summary>
        /// <param name="member">The member token to bind.</param>
        /// <returns>A FilterNode with the given path linked to it (if provided).</returns>
        internal ExpressionClause BindProperyExpression(QueryToken member)
        {
            ExceptionUtils.CheckArgumentNotNull(member, "filter");

            QueryNode expressionNode = this.bindMethod(member);

            SingleValueNode expressionResultNode = expressionNode as SingleValueNode;

            if (expressionResultNode == null)
            {
                throw new ODataException("The property expression must evaluate to a single value.");
            }

            // The type may be null here if the query statically represents the null literal or an open property.
            ExpressionClause res = new ExpressionClause(expressionResultNode, this.state.ImplicitRangeVariable);

            return(res);
        }
        /// <summary>
        /// Parses a <paramref name="query"/> clause on the given <paramref name="elementType"/>, binding
        /// the text into semantic nodes using the provided model.
        /// </summary>
        /// <param name="query">String representation of the filter expression.</param>
        /// <param name="configuration">The configuration used for binding.</param>
        /// <param name="elementType">Type that the filter clause refers to.</param>
        /// <param name="navigationSource">Navigation source that the elements being filtered are from.</param>
        /// <returns>A <see cref="FilterClause"/> representing the metadata bound filter expression.</returns>
        internal static ExpressionClause ParseExpressionImplementation(string query, ODataUriParserConfiguration configuration, IEdmType elementType, IEdmNavigationSource navigationSource)
        {
            ExceptionUtils.CheckArgumentNotNull(configuration, "configuration");
            ExceptionUtils.CheckArgumentNotNull(elementType, "elementType");
            ExceptionUtils.CheckArgumentNotNull(query, "query");

            // Get the syntactic representation of the filter expression
            UriQueryExpressionParser expressionParser = new UriQueryExpressionParser(configuration.Settings.FilterLimit);
            QueryToken expressionToken = expressionParser.ParseFilter(query);

            // Bind it to metadata
            BindingState state = new BindingState(configuration);

            state.ImplicitRangeVariable = NodeFactory.CreateImplicitRangeVariable(elementType.ToTypeReference(), navigationSource);
            state.RangeVariables.Push(state.ImplicitRangeVariable);
            MetadataBinder   binder       = new MetadataBinder(state);
            FilterBinder     filterBinder = new FilterBinder(binder.Bind, state);
            ExpressionClause boundNode    = filterBinder.BindProperyExpression(expressionToken);

            return(boundNode);
        }