本文整理汇总了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, ""));
}
示例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();
}
示例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();
}
示例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;
}
示例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);
}
示例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'.");
}
示例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);
}
}
示例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");
}
示例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");
}