Table of Contents

Class QueryOptions<TEntity>

Namespace
eQuantic.Core.Data.Repository.Options
Assembly
eQuantic.Core.Data.dll

Describes how a read query should be shaped: filtering, related data to include, sorting, change tracking and query-filter behaviour.

public class QueryOptions<TEntity> where TEntity : class

Type Parameters

TEntity

The type of the entity being queried.

Inheritance
QueryOptions<TEntity>
Inherited Members
Extension Methods

Remarks

A single QueryOptions<TEntity> instance replaces the large set of overloads previously exposed by the read repository interfaces. Options are composed through a fluent API and every method returns the same instance so calls can be chained.

Filters are best authored typed and fluent — Where/And/Or take a member selector (or a path string for dynamic columns), an operator and a value, folding left to right (Where(a).And(b).Or(c) is (a AND b) OR c). The raw Where(string, QueryStringOptions?) overload is meant for the boundary where a filter arrives as a query string; prefer the typed form for filters written in code.

Properties

AfterCustomization

Gets the transformation applied to the query after filtering and sorting, or null when none was supplied.

public Func<IQueryable<TEntity>, IQueryable<TEntity>>? AfterCustomization { get; }

Property Value

Func<IQueryable<TEntity>, IQueryable<TEntity>>

AsNoTracking

Gets a value indicating whether the query is executed without change tracking.

public bool AsNoTracking { get; }

Property Value

bool

BeforeCustomization

Gets the transformation applied to the query before filtering, or null when none was supplied.

public Func<IQueryable<TEntity>, IQueryable<TEntity>>? BeforeCustomization { get; }

Property Value

Func<IQueryable<TEntity>, IQueryable<TEntity>>

Filter

Gets the predicate used to filter the query, or null when no predicate was supplied.

public Expression<Func<TEntity, bool>>? Filter { get; }

Property Value

Expression<Func<TEntity, bool>>

IgnoreQueryFilters

Gets a value indicating whether global query filters are ignored for this query.

public bool IgnoreQueryFilters { get; }

Property Value

bool

IncludePaths

Gets the related property paths to eagerly load with the query.

public IReadOnlyCollection<string> IncludePaths { get; }

Property Value

IReadOnlyCollection<string>

Sortings

Gets the ordered set of sortings applied to the query.

public IReadOnlyList<QuerySort<TEntity>> Sortings { get; }

Property Value

IReadOnlyList<QuerySort<TEntity>>

Specification

Gets the specification used to filter the query, or null when no specification was supplied.

public ISpecification<TEntity>? Specification { get; }

Property Value

ISpecification<TEntity>

Tag

Gets the optional tag associated with the query, useful for logging and diagnostics.

public string? Tag { get; }

Property Value

string

Methods

And(string, FilterOperator, object?)

Adds a comparison clause combined with AND by path string.

public QueryOptions<TEntity> And(string path, FilterOperator op, object? value)

Parameters

path string

The member path.

op FilterOperator

The comparison operator.

value object

The value to compare against.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

And<TMember>(Expression<Func<TEntity, TMember>>, FilterOperator, TMember)

Adds a comparison clause combined with AND (reads naturally after Where<TMember>(Expression<Func<TEntity, TMember>>, FilterOperator, TMember)).

public QueryOptions<TEntity> And<TMember>(Expression<Func<TEntity, TMember>> selector, FilterOperator op, TMember value)

Parameters

selector Expression<Func<TEntity, TMember>>

The member selector.

op FilterOperator

The comparison operator.

value TMember

The value to compare against.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Type Parameters

TMember

The member type.

IgnoringQueryFilters()

Ignores global query filters for this query.

public QueryOptions<TEntity> IgnoringQueryFilters()

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Include(params string[])

Eagerly loads the supplied related property paths with the query.

public QueryOptions<TEntity> Include(params string[] paths)

Parameters

paths string[]

The property paths to include.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Exceptions

ArgumentNullException

Thrown when paths is null.

NoTracking()

Executes the query without change tracking.

public QueryOptions<TEntity> NoTracking()

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Or(string, FilterOperator, object?)

Adds a comparison clause combined with OR by path string.

public QueryOptions<TEntity> Or(string path, FilterOperator op, object? value)

Parameters

path string

The member path.

op FilterOperator

The comparison operator.

value object

The value to compare against.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Or<TMember>(Expression<Func<TEntity, TMember>>, FilterOperator, TMember)

Adds a comparison clause combined with OR: everything built so far OR this clause.

public QueryOptions<TEntity> Or<TMember>(Expression<Func<TEntity, TMember>> selector, FilterOperator op, TMember value)

Parameters

selector Expression<Func<TEntity, TMember>>

The member selector.

op FilterOperator

The comparison operator.

value TMember

The value to compare against.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Type Parameters

TMember

The member type.

OrderBy(string, QueryStringOptions?)

Appends the sortings parsed from an eQuantic.Linq.Web ordering expression, e.g. total:desc,customer.name (direction defaults to ascending), preserving their order.

public QueryOptions<TEntity> OrderBy(string orderBy, QueryStringOptions? options = null)

Parameters

orderBy string

The ordering expression to parse and apply.

options QueryStringOptions

Optional query-string parsing options.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Exceptions

ArgumentNullException

Thrown when orderBy is null.

OrderBy(params QuerySort<TEntity>[])

Appends the supplied sortings to the query, preserving their order.

public QueryOptions<TEntity> OrderBy(params QuerySort<TEntity>[] sortings)

Parameters

sortings QuerySort<TEntity>[]

The sortings to apply.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Exceptions

ArgumentNullException

Thrown when sortings is null.

OrderByDescending(string)

Appends a descending sort by path string.

public QueryOptions<TEntity> OrderByDescending(string path)

Parameters

path string

The member path.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

OrderByDescending<TKey>(Expression<Func<TEntity, TKey>>)

Appends a descending sort by the selected member (the primary sort).

public QueryOptions<TEntity> OrderByDescending<TKey>(Expression<Func<TEntity, TKey>> selector)

Parameters

selector Expression<Func<TEntity, TKey>>

The member selector.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Type Parameters

TKey

The member type.

OrderBy<TKey>(Expression<Func<TEntity, TKey>>)

Appends an ascending sort by the selected member (the primary sort).

public QueryOptions<TEntity> OrderBy<TKey>(Expression<Func<TEntity, TKey>> selector)

Parameters

selector Expression<Func<TEntity, TKey>>

The member selector.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Type Parameters

TKey

The member type.

ThenBy(string)

Appends an ascending secondary sort by path string.

public QueryOptions<TEntity> ThenBy(string path)

Parameters

path string

The member path.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

ThenByDescending(string)

Appends a descending secondary sort by path string.

public QueryOptions<TEntity> ThenByDescending(string path)

Parameters

path string

The member path.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

ThenByDescending<TKey>(Expression<Func<TEntity, TKey>>)

Appends a descending secondary sort by the selected member.

public QueryOptions<TEntity> ThenByDescending<TKey>(Expression<Func<TEntity, TKey>> selector)

Parameters

selector Expression<Func<TEntity, TKey>>

The member selector.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Type Parameters

TKey

The member type.

ThenBy<TKey>(Expression<Func<TEntity, TKey>>)

Appends an ascending secondary sort by the selected member.

public QueryOptions<TEntity> ThenBy<TKey>(Expression<Func<TEntity, TKey>> selector)

Parameters

selector Expression<Func<TEntity, TKey>>

The member selector.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Type Parameters

TKey

The member type.

Where(Expression<Func<TEntity, bool>>)

Filters the query using the supplied predicate.

public QueryOptions<TEntity> Where(Expression<Func<TEntity, bool>> filter)

Parameters

filter Expression<Func<TEntity, bool>>

The predicate to apply.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Exceptions

ArgumentNullException

Thrown when filter is null.

Where(string, FilterOperator, object?)

Adds a comparison clause combined with AND by path string (for dynamic column names); the operator and value stay typed. The path can carry aggregate/method segments (items.count()).

public QueryOptions<TEntity> Where(string path, FilterOperator op, object? value)

Parameters

path string

The member path.

op FilterOperator

The comparison operator.

value object

The value to compare against.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Where(string, QueryStringOptions?)

Filters the query using an eQuantic.Linq.Web filter expression, e.g. name:eq(John),age:gt(18). Intended for the boundary where a filter arrives as a query string; for filters written in code prefer the typed Where/And/Or.

public QueryOptions<TEntity> Where(string filter, QueryStringOptions? options = null)

Parameters

filter string

The filter expression to parse and apply.

options QueryStringOptions

Optional query-string parsing options.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Exceptions

ArgumentNullException

Thrown when filter is null.

Where(ExpressionModel<TEntity>, ExpressionSerializer?)

Filters the query using a serialized eQuantic.Linq.Expressions.ExpressionModel<TRoot> — a filter built in code or received over the wire goes straight in, no query string in the middle.

public QueryOptions<TEntity> Where(ExpressionModel<TEntity> model, ExpressionSerializer? serializer = null)

Parameters

model ExpressionModel<TEntity>

The serializable filter model.

serializer ExpressionSerializer

Optional serializer; the default applies when omitted.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Exceptions

ArgumentNullException

Thrown when model is null.

Where(ISpecification<TEntity>)

Filters the query using the supplied specification.

public QueryOptions<TEntity> Where(ISpecification<TEntity> specification)

Parameters

specification ISpecification<TEntity>

The specification to apply.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Exceptions

ArgumentNullException

Thrown when specification is null.

Where<TMember>(Expression<Func<TEntity, TMember>>, FilterOperator, TMember)

Adds a comparison clause combined with AND, e.g. o => o.Total greater than 100. Clauses fold left to right; consecutive AND clauses flatten into a single filter.

public QueryOptions<TEntity> Where<TMember>(Expression<Func<TEntity, TMember>> selector, FilterOperator op, TMember value)

Parameters

selector Expression<Func<TEntity, TMember>>

The member selector.

op FilterOperator

The comparison operator.

value TMember

The value to compare against.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Type Parameters

TMember

The member type.

WithAfterCustomization(Func<IQueryable<TEntity>, IQueryable<TEntity>>)

Applies a custom transformation to the query after filtering and sorting are applied.

public QueryOptions<TEntity> WithAfterCustomization(Func<IQueryable<TEntity>, IQueryable<TEntity>> customize)

Parameters

customize Func<IQueryable<TEntity>, IQueryable<TEntity>>

The transformation to apply.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Exceptions

ArgumentNullException

Thrown when customize is null.

WithBeforeCustomization(Func<IQueryable<TEntity>, IQueryable<TEntity>>)

Applies a custom transformation to the query before filtering is applied.

public QueryOptions<TEntity> WithBeforeCustomization(Func<IQueryable<TEntity>, IQueryable<TEntity>> customize)

Parameters

customize Func<IQueryable<TEntity>, IQueryable<TEntity>>

The transformation to apply.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Exceptions

ArgumentNullException

Thrown when customize is null.

WithTag(string)

Associates a diagnostic tag with the query.

public QueryOptions<TEntity> WithTag(string tag)

Parameters

tag string

The tag to associate.

Returns

QueryOptions<TEntity>

The same QueryOptions<TEntity> instance for chaining.

Exceptions

ArgumentNullException

Thrown when tag is null.