-
Notifications
You must be signed in to change notification settings - Fork 1
Net.Http.OData.Query
The Query Options describe an OData query which has been made against the OData service, the following classes and their public members are contained within the namespace Net.Http.OData.Query
.
Contains deserialised values from the $filter
query option.
Property | Description |
---|---|
QueryNode Expression { get; } | Gets the expression. |
Contains deserialised values from the $format
query option.
Property | Description |
---|---|
MediaTypeHeaderValue MediaTypeHeaderValue { get; } | Gets the media type header value. |
The interface for an ODataQueryOptions validator.
Method | Description |
---|---|
void Validate(ODataQueryOptions queryOptions, ODataValidationSettings validationSettings) | Validates the specified query options using the specified validation settings. |
Contains the query options in an OData query.
Property | Description |
---|---|
bool Count { get; } | Gets a value indicating whether the count query option has been specified. |
EntitySet EntitySet { get; } | Gets the EntitySet to apply the OData query against. |
SelectExpandQueryOption Expand { get; } | Gets SelectExpandQueryOption which represents the $expand query option. |
FilterQueryOption Filter { get; } | Gets FilterQueryOption which represents the $filter query option. |
FormatQueryOption Format { get; } | Gets FormatQueryOption which represents the $format query option. |
OrderByQueryOption OrderBy { get; } | Gets OrderByQueryOption which represents the $orderby query option. |
ODataRawQueryOptions RawValues { get; } | Gets the raw values of the OData query request. |
SearchQueryOption Search { get; } | Gets SearchQueryOption which represents the $search query option. |
SelectExpandQueryOption Select { get; } | Gets SelectExpandQueryOption which represents the $select query option. |
int? Skip { get; } | Gets the integer value specified in the $skip query option. |
SkipTokenQueryOption SkipToken { get; } | Gets SkipTokenQueryOption which represents the $skiptoken query option. |
int? Top { get; } | Gets the integer value specified in the $top query option. |
Method | Description |
---|---|
static IODataQueryOptionsValidator GetValidator(ODataVersion odataVersion) | Gets the IODataQueryOptionsValidator for the specified ODataVersion. |
Contains the raw query options in an OData query.
Property | Description |
---|---|
string Count { get; } | Gets the raw $count query value from the incoming request Uri if specified. |
string Expand { get; } | Gets the raw $expand query value from the incoming request Uri if specified. |
string Filter { get; } | Gets the raw $filter query value from the incoming request Uri if specified. |
string Format { get; } | Gets the raw $format query value from the incoming request Uri if specified. |
string OrderBy { get; } | Gets the raw $orderby query value from the incoming request Uri if specified. |
string Search { get; } | Gets the raw $search query value from the incoming request Uri if specified. |
string Select { get; } | Gets the raw $select query value from the incoming request Uri if specified. |
string Skip { get; } | Gets the raw $skip query value from the incoming request Uri if specified. |
string SkipToken { get; } | Gets the raw $skiptoken query value from the incoming request Uri if specified. |
string Top { get; } | Gets the raw $top query value from the incoming request Uri if specified. |
Defines the validation settings to use when validating values in ODataQueryOptions.
Property | Description |
---|---|
static ODataValidationSettings All | Gets the validation settings for when all OData queries are allowed. |
static ODataValidationSettings None | Gets the validation settings for when no OData queries are allowed. |
AllowedArithmeticOperators AllowedArithmeticOperators { get; set; } | Gets or sets the allowed arithmetic operators. |
AllowedFunctions AllowedFunctions { get; set; } | Gets or sets the allowed functions. |
AllowedLogicalOperators AllowedLogicalOperators { get; set; } | Gets or sets the allowed logical operators. |
AllowedQueryOptions AllowedQueryOptions { get; set; } | Gets or sets the allowed query options. |
int MaxTop { get; set; } | Gets or sets the max value allowed in the $top query option. |
Property | Description |
---|---|
Ascending | The results are to be filtered by the named property in ascending order. |
Descending | The results are to be filtered by the named property in descending order. |
Represents an order by property expression in the $orderby
query option.
Property | Description |
---|---|
OrderByDirection Direction { get; } | Gets the direction the property should be ordered by. |
PropertyPath PropertyPath { get; } | Gets the property path to order by. |
string RawValue { get; } | Gets the raw request value. |
Contains deserialised values from the $orderby
query option.
Property | Description |
---|---|
IReadOnlyList<OrderByProperty> Properties { get; } | Gets the properties the query should be ordered by. |
The base class for an OData System Query Option.
Property | Description |
---|---|
string RawValue { get; } | Gets the raw request value. |
Contains deserialised values from the $search
query option.
Contains deserialised values from the $select
or $expand
query option.
Property | Description |
---|---|
IReadOnlyList<PropertyPath> PropertyPaths { get; } | Gets the property paths specified in the query. |
Contains deserialised values from the $skiptoken
query option.
The library contains 3 base classes to help with parsing OData Queries. Although you do not have to use them, they are intended to make it easier to implement parsing logic. The classes are in the namespace Net.Http.OData.Query.Binders
.
Provides a template for binding the FilterQueryOption
public class FilterBinder : AbstractFilterBinder
{
private StringBuilder _stringBuilder;
public FilterBinder(StringBuilder stringBuilder) => _stringBuilder = stringBuilder;
protected override void Bind(BinaryOperatorNode binaryOperatorNode)
{
_stringBuilder.AppendLine();
Bind(binaryOperatorNode.Left);
_stringBuilder.Append(binaryOperatorNode.OperatorKind.ToString());
Bind(binaryOperatorNode.Right);
}
protected override void Bind(ConstantNode constantNode)
{
if (constantNode.EdmType == null)
{
_stringBuilder.Append("NULL");
}
else
{
_stringBuilder.Append(constantNode.Value.ToString());
}
}
protected override void Bind(FunctionCallNode functionCallNode)
{
_stringBuilder.Append(functionCallNode.Name);
foreach (var parameter in functionCallNode.Parameters)
{
Bind(parameter);
}
}
protected override void Bind(PropertyAccessNode propertyAccessNode)
{
var propertyPath = propertyAccessNode.PropertyPath;
while (propertyPath != null)
{
_stringBuilder.Append(propertyPath.Property.Name);
if (propertyPath.Next != null)
{
_stringBuilder.Append(".");
}
propertyPath = propertyPath.Next;
}
_stringBuilder.AppendLine();
}
protected override void Bind(UnaryOperatorNode unaryOperatorNode)
{
_stringBuilder.Append(unaryOperatorNode.OperatorKind.ToString());
Bind(unaryOperatorNode.Operand);
}
}
Provides a template for binding the OrderByQueryOption
public class OrderByBinder : AbstractOrderByBinder
{
private StringBuilder _stringBuilder;
public OrderByBinder(StringBuilder stringBuilder) => _stringBuilder = stringBuilder;
protected override void Bind(OrderByProperty orderByProperty)
{
var propertyPath = orderByProperty.PropertyPath;
while (propertyPath != null)
{
_stringBuilder.Append(propertyPath.Property.Name);
if (propertyPath.Next != null)
{
_stringBuilder.Append(".");
}
propertyPath = propertyPath.Next;
}
_stringBuilder.Append(" ").AppendLine(orderByProperty.Direction.ToString());
}
}
Provides a template for binding the SelectExpandQueryOption
public class SelectExpandBinder : AbstractSelectExpandBinder
{
private StringBuilder _stringBuilder;
public SelectExpandBinder(StringBuilder stringBuilder) => _stringBuilder = stringBuilder;
protected override void Bind(PropertyPath propertyPath)
{
while (propertyPath != null)
{
_stringBuilder.Append(propertyPath.Property.Name);
if (propertyPath.Next != null)
{
_stringBuilder.Append(".");
}
propertyPath = propertyPath.Next;
}
_stringBuilder.AppendLine();
}
}
var stringBuilder = new StringBuilder();
var selectExpandBinder = new SelectExpandBinder(stringBuilder);
selectExpandBinder.Bind(queryOptions.Select);
selectExpandBinder.Bind(queryOptions.Expand);
var filterBinder = new FilterBinder(stringBuilder);
filterBinder.Bind(queryOptions.Filter);
var orderByBinder = new OrderByBinder(stringBuilder);
orderByBinder.Bind(queryOptions.OrderBy);
The kinds of binary operator.
Property | Description |
---|---|
Or | |
And | |
Equal | |
NotEqual | |
GreaterThan | |
GreaterThanOrEqual | |
LessThan | |
LessThanOrEqual | |
Add | |
Subtract | |
Multiply | |
Divide | |
Modulo | |
Has |
A QueryNode which represents a binary operator with a left and right branch.
Property | Description |
---|---|
QueryNode Left { get; } | Gets the left query node. |
BinaryOperatorKind OperatorKind { get; } | Gets the kind of the operator. |
QueryNode Right { get; internal set; } | Gets the right query node. |
A QueryNode which represents a constant value.
Property | Description |
---|---|
EdmType EdmType { get; } | Gets the EdmType of the value. |
string LiteralText { get; } | Gets the literal text if the constant value. |
object Value { get; } | Gets the constant value as an object. |
If the value in this ConstantNode is a Value Type, it will be boxed on demand by calling the Value getter. To avoid boxing/unboxing then cast this ConstantNode to the appropriate ConstantNode<T> and acces the value via that instead.
A QueryNode which represents a strongly typed constant value.
Property | Description |
---|---|
T Value { get; } | Gets the constant value. |
A QueryNode which represents a function call.
Property | Description |
---|---|
string Name { get; } | Gets the name of the function. |
IReadOnlyList<QueryNode> Parameters { get; } | Gets the parameters for the function call. |
A QueryNode which represents a property.
Property | Description |
---|---|
PropertyPath PropertyPath { get; } | Gets the property path being referenced in the query. |
Represents a property path.
Property | Description |
---|---|
PropertyPath Next { get; } | Gets the next property in the path being referenced in the query, or null if this instance is the last (or only) property in the path. |
EdmProperty Property { get; } | Gets the EdmProperty representing the property being referenced in the query. |
The base class for a query node.
Property | Description |
---|---|
abstract QueryNodeKind Kind { get; } | Gets the kind of query node. |
Property | Description |
---|---|
BinaryOperator | |
PropertyAccess | |
Constant | |
FunctionCall | |
UnaryOperator |
Property | Description |
---|---|
Not |
A QueryNode which represents a unary operator.
Property | Description |
---|---|
QueryNode Operand { get; } | Gets the operand of the unary operator. |
UnaryOperatorKind OperatorKind { get; } | Gets the kind of the operator. |
Contains settings used by the parsers.
Property | Description |
---|---|
static DateTimeStyles DateTimeStyles { get; set; } | Gets or sets the DateTimeStyles to use for parsing DateTimeOffset if no timezone is specified in the OData query (defaults to AssumeUniversal). |