ODataQuery<T> Class

Builds the OData query options $filter, $expand, $orderby, $skip, $top, $count and $apply for the entity set of T from lambda expressions, with the method names of Entity Framework Core. Every method returns a new query and leaves the one it was called on unchanged. A value a lambda captures is read when the method is called. Pass the query to LoadDataArgs) to get the request URI.

Inheritance

Object

ODataQuery<T>

Namespace: Radzen

Assembly: Radzen.Blazor.dll

Syntax

public class ODataQuery<T>

Type Parameters

Name Description
TThe entity type of the entity set.

Examples

var query = new ODataQuery<Ticket>()
    .Where(ticket => ticket.Status == TicketStatus.Open && ticket.Subject.Contains(search))
    .Include(ticket => ticket.Team).ThenInclude(team => team.Schedule)
    .OrderByDescending(ticket => ticket.CreatedAt)
    .Take(10);
var uri = new Uri(baseUri, "Tickets").GetODataUri(query);

Constructors

ODataQuery<T>Link to this section

Initializes a new query that has no options.

Declaration
public ODataQuery<T>()

Methods

GroupByLink to this section

Groups the entities by keySelector for a Select of the group keys and aggregates, translated to $apply=groupby(...), or to $apply=aggregate(...) when the key is a constant such as 1, which puts every entity in one group. Every Where before it becomes a filter(...) transformation that runs before the grouping.

Declaration
public GroupedODataQuery<T, TKey> GroupBy(Expressions.Expression<Func<T, TKey>> keySelector)
Parameters
Type Name Description
Expressions.Expression<Func<T, TKey>> keySelector The key, e.g. license => license.Currency, license => new { license.Currency, license.Country } or license => 1.
Returns
Type Description
GroupedODataQuery<T, TKey>A grouping on which Select sets the result.

IncludeLink to this section

Expands the navigation property that navigation selects, translated to $expand. A path such as ticket => ticket.Team.Schedule expands each level, and a collection can be filtered, ordered and paged with Where, OrderBy, OrderByDescending, ThenBy, ThenByDescending, Skip and Take, e.g. ticket => ticket.Comments.OrderByDescending(comment => comment.CreatedAt).Take(3).

Declaration
public IncludableODataQuery<T, TProperty> Include(Expressions.Expression<Func<T, TProperty>> navigation)
Parameters
Type Name Description
Expressions.Expression<Func<T, TProperty>> navigation The navigation property.
Returns
Type Description
IncludableODataQuery<T, TProperty>A new query to which Func{``1,``2}}) adds the next level.

OrderByLink to this section

Orders the entities by keySelector ascending, translated to $orderby. Replaces any earlier ordering.

Declaration
public OrderedODataQuery<T> OrderBy(Expressions.Expression<Func<T, TKey>> keySelector)
Parameters
Type Name Description
Expressions.Expression<Func<T, TKey>> keySelector The key, e.g. ticket => ticket.Team.Name.
Returns
Type Description
OrderedODataQuery<T>A new query to which ThenBy adds the next key.

OrderByDescendingLink to this section

Orders the entities by keySelector descending, translated to $orderby. Replaces any earlier ordering.

Declaration
public OrderedODataQuery<T> OrderByDescending(Expressions.Expression<Func<T, TKey>> keySelector)
Parameters
Type Name Description
Expressions.Expression<Func<T, TKey>> keySelector The key, e.g. ticket => ticket.CreatedAt.
Returns
Type Description
OrderedODataQuery<T>A new query to which ThenBy adds the next key.

SkipLink to this section

Skips count entities, translated to $skip. Call it once, before Int32).

Declaration
public ODataQuery<T> Skip(int count)
Parameters
Type Name Description
int count The number of entities to skip.
Returns
Type Description
ODataQuery<T>A new query with $skip.

TakeLink to this section

Takes at most count entities, translated to $top. Call it once.

Declaration
public ODataQuery<T> Take(int count)
Parameters
Type Name Description
int count The number of entities to return.
Returns
Type Description
ODataQuery<T>A new query with $top.

ToQueryStringLink to this section

Returns the query options with each value escaped once with String), e.g. $filter=Name%20eq%20%27O%27%27Brien%27&$top=10.

Declaration
public string ToQueryString()
Returns
Type Description
stringThe query string without the leading question mark, or an empty string when the query has no options.

ToStringLink to this section

Returns the query options unescaped, e.g. $filter=Name eq 'O''Brien'&$top=10.

Declaration
public override string ToString()
Returns
Type Description
stringThe readable query options.

WhereLink to this section

Filters the entities with predicate, translated to $filter. Repeated calls combine with and.

Declaration
public ODataQuery<T> Where(Expressions.Expression<Func<T, bool>> predicate)
Parameters
Type Name Description
Expressions.Expression<Func<T, bool>> predicate The condition, e.g. ticket => ticket.Status == TicketStatus.Open.
Returns
Type Description
ODataQuery<T>A new query with the filter added.

WithCountLink to this section

Requests the total count of the filtered entities, translated to $count=true.

Declaration
public ODataQuery<T> WithCount()
Returns
Type Description
ODataQuery<T>A new query with $count=true.
An error has occurred. This app may no longer respond until reloaded. Reload 🗙