Esempio n. 1
0
        /// <summary>
        /// Bind a filter option
        /// </summary>
        /// <param name="syntax">a syntactic tree containing the filter option</param>
        /// <param name="rangeVariable">the range variable that iterates over the top level collection.</param>
        /// <returns>A filter clause representing this filter option</returns>
        public FilterClause BindFilter(SyntacticTree syntax, RangeVariable rangeVariable)
        {
            if (syntax.Filter != null)
            {
                if (rangeVariable == null)
                {
                    throw new ODataException(ODataErrorStrings.MetadataBinder_QueryOptionNotApplicable("$filter"));
                }

                FilterBinder filterBinder = new FilterBinder(this.bindMethod, this.bindingState);
                return(filterBinder.BindFilter(syntax.Filter));
            }

            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Parses a <paramref name="filter"/> clause on the given <paramref name="elementType"/>, binding
        /// the text into semantic nodes using the provided.
        /// </summary>
        /// <param name="filter">String representation of the filter expression.</param>
        /// <param name="elementType">Type that the filter clause refers to.</param>
        /// <param name="entitySet">EntitySet that the elements beign filtered are from.</param>
        /// <returns>A <see cref="FilterClause"/> representing the metadata bound filter expression.</returns>
        private FilterClause ParseFilterImplementation(string filter, IEdmType elementType, IEdmEntitySet entitySet)
        {
            ExceptionUtils.CheckArgumentNotNull(this.configuration, "this.configuration");
            ExceptionUtils.CheckArgumentNotNull(elementType, "elementType");
            ExceptionUtils.CheckArgumentNotNull(filter, "filter");

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

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

            state.ImplicitRangeVariable = NodeFactory.CreateImplicitRangeVariable(elementType.ToTypeReference(), entitySet);
            state.RangeVariables.Push(state.ImplicitRangeVariable);
            MetadataBinder binder       = new MetadataBinder(state);
            FilterBinder   filterBinder = new FilterBinder(binder.Bind, state);
            FilterClause   boundNode    = filterBinder.BindFilter(filterToken);

            return(boundNode);
        }