当前位置: 首页>>代码示例>>C#>>正文


C# ODataQueryOptionParser.ParseFilter方法代码示例

本文整理汇总了C#中Microsoft.OData.Core.UriParser.ODataQueryOptionParser.ParseFilter方法的典型用法代码示例。如果您正苦于以下问题:C# ODataQueryOptionParser.ParseFilter方法的具体用法?C# ODataQueryOptionParser.ParseFilter怎么用?C# ODataQueryOptionParser.ParseFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.OData.Core.UriParser.ODataQueryOptionParser的用法示例。


在下文中一共展示了ODataQueryOptionParser.ParseFilter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: QueryOptionWithEmptyValueShouldWork

        public void QueryOptionWithEmptyValueShouldWork()
        {
            var uriParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet(), new Dictionary<string, string>()
            {
                {"$filter"  , ""},
                {"$expand"  , ""},
                {"$select"  , ""},
                {"$orderby" , ""},
                {"$top"     , ""},
                {"$skip"    , ""},
                {"$count"   , ""},
                {"$search"  , ""},
                {"$unknow"  , ""},
            });

            uriParser.ParseFilter().Should().BeNull();
            var results = uriParser.ParseSelectAndExpand();
            results.AllSelected.Should().BeTrue();
            results.SelectedItems.Should().HaveCount(0);
            uriParser.ParseOrderBy().Should().BeNull();
            Action action = () => uriParser.ParseTop();
            action.ShouldThrow<ODataException>().WithMessage(Strings.SyntacticTree_InvalidTopQueryOptionValue(""));
            action = () => uriParser.ParseSkip();
            action.ShouldThrow<ODataException>().WithMessage(Strings.SyntacticTree_InvalidSkipQueryOptionValue(""));
            action = () => uriParser.ParseCount();
            action.ShouldThrow<ODataException>().WithMessage(Strings.ODataUriParser_InvalidCount(""));
            action = () => uriParser.ParseSearch();
            action.ShouldThrow<ODataException>().WithMessage(Strings.UriQueryExpressionParser_ExpressionExpected(0, ""));
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:29,代码来源:ODataQueryOptionParserUnitTests.cs

示例2: EmptyQueryOptionDictionaryShouldWork

 public void EmptyQueryOptionDictionaryShouldWork()
 {
     var uriParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet(), new Dictionary<string, string>());
     uriParser.ParseFilter().Should().BeNull();
     uriParser.ParseSelectAndExpand().Should().BeNull();
     uriParser.ParseOrderBy().Should().BeNull();
     uriParser.ParseTop().Should().Be(null);
     uriParser.ParseSkip().Should().Be(null);
     uriParser.ParseCount().Should().Be(null);
     uriParser.ParseSearch().Should().BeNull();
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:11,代码来源:ODataQueryOptionParserUnitTests.cs

示例3: QueryOptionWithNullValueShouldWork

        public void QueryOptionWithNullValueShouldWork()
        {
            var uriParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet(), new Dictionary<string, string>()
            {
                {"$filter"  , null},
                {"$expand"  , null},
                {"$select"  , null},
                {"$orderby" , null},
                {"$top"     , null},
                {"$skip"    , null},
                {"$count"   , null},
                {"$search"  , null},
                {"$unknow"  , null},
            });

            uriParser.ParseFilter().Should().BeNull();
            uriParser.ParseSelectAndExpand().Should().BeNull();
            uriParser.ParseOrderBy().Should().BeNull();
            uriParser.ParseTop().Should().Be(null);
            uriParser.ParseSkip().Should().Be(null);
            uriParser.ParseCount().Should().Be(null);
            uriParser.ParseSearch().Should().BeNull();
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:23,代码来源:ODataQueryOptionParserUnitTests.cs

示例4: TranslateFilterExpression

 private QueryNode TranslateFilterExpression(string filter)
 {
     var parser = new ODataQueryOptionParser(_model, _customerEntityType, _customersEntitySet,
         new Dictionary<string, string> { { "$filter", filter } });
     FilterClause filterClause = parser.ParseFilter();
     var translator = new ParameterAliasNodeTranslator(
         new Dictionary<string, SingleValueNode> { { "@p", _parameterAliasMappedNode } });
     QueryNode translatedNode = filterClause.Expression.Accept(translator);
     return translatedNode;
 }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:10,代码来源:ParameterAliasNodeTranslatorTest.cs

示例5: CreatePropertyValueExpressionWithFilter_Works_HandleNullPropagationOptionIsFalse

        public void CreatePropertyValueExpressionWithFilter_Works_HandleNullPropagationOptionIsFalse()
        {
            // Arrange
            _model.Model.SetAnnotationValue(_model.Order, new ClrTypeAnnotation(typeof(Order)));
            _settings.HandleNullPropagation = HandleNullPropagationOption.False;
            var customer =
                Expression.Constant(new Customer { Orders = new[] { new Order { ID = 1 }, new Order { ID = 2 } } });
            var ordersProperty = _model.Customer.NavigationProperties().Single(p => p.Name == "Orders");
            var parser = new ODataQueryOptionParser(
                _model.Model,
                _model.Order,
                _model.Orders,
                new Dictionary<string, string> { { "$filter", "ID eq 1" } });
            var filterCaluse = parser.ParseFilter();

            // Act
            var filterInExpand = _binder.CreatePropertyValueExpressionWithFilter(
                _model.Customer,
                ordersProperty,
                customer,
                filterCaluse);

            // Assert
            Assert.Equal(
                string.Format(
                    "value({0}).Orders.AsQueryable().Where($it => ($it.ID == value(" +
                    "System.Web.OData.Query.Expressions.LinqParameterContainer+TypedLinqParameterContainer`1[System.Int32]).TypedProperty))",
                    customer.Type),
                filterInExpand.ToString());
            var orders = Expression.Lambda(filterInExpand).Compile().DynamicInvoke() as IEnumerable<Order>;
            Assert.Single(orders);
            Assert.Equal(1, orders.ToList()[0].ID);
        }
开发者ID:shailendra9,项目名称:WebApi,代码行数:33,代码来源:SelectExpandBinderTest.cs

示例6: CreatePropertyValueExpressionWithFilter_ThrowsODataException_IfMappingTypeIsNotFoundInModel

        public void CreatePropertyValueExpressionWithFilter_ThrowsODataException_IfMappingTypeIsNotFoundInModel()
        {
            // Arrange
            _model.Model.SetAnnotationValue<ClrTypeAnnotation>(_model.Order, value: null);
            var customer = Expression.Constant(new Customer());
            var ordersProperty = _model.Customer.NavigationProperties().Single(p => p.Name == "Orders");
            var parser = new ODataQueryOptionParser(
                _model.Model,
                _model.Order,
                _model.Orders,
                new Dictionary<string, string> { { "$filter", "ID eq 1" } });
            var filterCaluse = parser.ParseFilter();

            // Act & Assert
            Assert.Throws<ODataException>(
                () => _binder.CreatePropertyValueExpressionWithFilter(_model.Customer, ordersProperty, customer, filterCaluse),
                "The provided mapping does not contain an entry for the entity type 'NS.Order'.");
        }
开发者ID:shailendra9,项目名称:WebApi,代码行数:18,代码来源:SelectExpandBinderTest.cs

示例7: ParseUriAndVerify

        private void ParseUriAndVerify(
            Uri uri,
            Action<ODataPath, FilterClause, OrderByClause, SelectExpandClause, IDictionary<string, SingleValueNode>> verifyAction)
        {
            // run 2 test passes:
            // 1. low level api - ODataUriParser instance methods
            {
                List<CustomQueryOptionToken> queries = UriUtils.ParseQueryOptions(uri);
                ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://gobbledygook/"), uri);

                ODataPath path = parser.ParsePath();
                IEdmNavigationSource entitySource = ResolveEntitySource(path);
                IEdmEntitySet entitySet = entitySource as IEdmEntitySet;

                var dic = queries.ToDictionary(customQueryOptionToken => customQueryOptionToken.Name, customQueryOptionToken => queries.GetQueryOptionValue(customQueryOptionToken.Name));
                ODataQueryOptionParser queryOptionParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel, entitySet.EntityType(), entitySet, dic)
                {
                    Configuration = { ParameterAliasValueAccessor = parser.ParameterAliasValueAccessor }
                };

                FilterClause filterClause = queryOptionParser.ParseFilter();
                SelectExpandClause selectExpandClause = queryOptionParser.ParseSelectAndExpand();
                OrderByClause orderByClause = queryOptionParser.ParseOrderBy();

                // Two parser should share same ParameterAliasNodes
                verifyAction(path, filterClause, orderByClause, selectExpandClause, parser.ParameterAliasNodes);
                verifyAction(path, filterClause, orderByClause, selectExpandClause, queryOptionParser.ParameterAliasNodes);
            }

            //2. high level api - ParseUri
            {
                ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://gobbledygook/"), uri);
                verifyAction(parser.ParsePath(), parser.ParseFilter(), parser.ParseOrderBy(), parser.ParseSelectAndExpand(), parser.ParameterAliasNodes);
            }
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:35,代码来源:ParameterAliasFunctionalTests.cs

示例8: AggregatedPropertiesTreatedAsOpenProperty

 public void AggregatedPropertiesTreatedAsOpenProperty()
 {
     var odataQueryOptionParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel,
         HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet(),
         new Dictionary<string, string>()
         {
             {"$filter", "Total ge 10 and Max le 2"},
             {"$apply", "aggregate(FavoriteNumber with sum as Total, StockQuantity with max as Max)"}
         });
     odataQueryOptionParser.ParseApply();
     var filterClause = odataQueryOptionParser.ParseFilter();
     var binaryOperatorNode = filterClause.Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.And).And;
     var leftBinaryOperatorNode =
         binaryOperatorNode.Left.ShouldBeBinaryOperatorNode(BinaryOperatorKind.GreaterThanOrEqual).And;
     var rightBinaryOperatorNode =
         binaryOperatorNode.Right.ShouldBeBinaryOperatorNode(BinaryOperatorKind.LessThanOrEqual).And;
     leftBinaryOperatorNode.Left.As<ConvertNode>().Source.ShouldBeSingleValueOpenPropertyAccessQueryNode("Total");
     rightBinaryOperatorNode.Left.As<ConvertNode>().Source.ShouldBeSingleValueOpenPropertyAccessQueryNode("Max");
 }
开发者ID:TomDu,项目名称:odata.net,代码行数:19,代码来源:FilterAndOrderByFunctionalTests.cs

示例9: AggregatedPropertyTreatedAsOpenProperty

 public void AggregatedPropertyTreatedAsOpenProperty()
 {
     var odataQueryOptionParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel,
         HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet(),
         new Dictionary<string, string>()
         {
             {"$filter", "Total"},
             {"$apply", "aggregate(FavoriteNumber with sum as Total)"}
         });
     odataQueryOptionParser.ParseApply();
     var filterClause = odataQueryOptionParser.ParseFilter();
     filterClause.Expression.ShouldBeSingleValueOpenPropertyAccessQueryNode("Total");
 }
开发者ID:TomDu,项目名称:odata.net,代码行数:13,代码来源:FilterAndOrderByFunctionalTests.cs


注:本文中的Microsoft.OData.Core.UriParser.ODataQueryOptionParser.ParseFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。