-
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. |
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);
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. |
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. |
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. |