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
TEntityThe 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
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
IncludePaths
Gets the related property paths to eagerly load with the query.
public IReadOnlyCollection<string> IncludePaths { get; }
Property Value
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
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
pathstringThe member path.
opFilterOperatorThe comparison operator.
valueobjectThe 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
selectorExpression<Func<TEntity, TMember>>The member selector.
opFilterOperatorThe comparison operator.
valueTMemberThe value to compare against.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Type Parameters
TMemberThe 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
pathsstring[]The property paths to include.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Exceptions
- ArgumentNullException
Thrown when
pathsisnull.
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
pathstringThe member path.
opFilterOperatorThe comparison operator.
valueobjectThe 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
selectorExpression<Func<TEntity, TMember>>The member selector.
opFilterOperatorThe comparison operator.
valueTMemberThe value to compare against.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Type Parameters
TMemberThe 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
orderBystringThe ordering expression to parse and apply.
optionsQueryStringOptionsOptional query-string parsing options.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Exceptions
- ArgumentNullException
Thrown when
orderByisnull.
OrderBy(params QuerySort<TEntity>[])
Appends the supplied sortings to the query, preserving their order.
public QueryOptions<TEntity> OrderBy(params QuerySort<TEntity>[] sortings)
Parameters
sortingsQuerySort<TEntity>[]The sortings to apply.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Exceptions
- ArgumentNullException
Thrown when
sortingsisnull.
OrderByDescending(string)
Appends a descending sort by path string.
public QueryOptions<TEntity> OrderByDescending(string path)
Parameters
pathstringThe 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
selectorExpression<Func<TEntity, TKey>>The member selector.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Type Parameters
TKeyThe 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
selectorExpression<Func<TEntity, TKey>>The member selector.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Type Parameters
TKeyThe member type.
ThenBy(string)
Appends an ascending secondary sort by path string.
public QueryOptions<TEntity> ThenBy(string path)
Parameters
pathstringThe 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
pathstringThe 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
selectorExpression<Func<TEntity, TKey>>The member selector.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Type Parameters
TKeyThe 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
selectorExpression<Func<TEntity, TKey>>The member selector.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Type Parameters
TKeyThe member type.
Where(Expression<Func<TEntity, bool>>)
Filters the query using the supplied predicate.
public QueryOptions<TEntity> Where(Expression<Func<TEntity, bool>> filter)
Parameters
filterExpression<Func<TEntity, bool>>The predicate to apply.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Exceptions
- ArgumentNullException
Thrown when
filterisnull.
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
pathstringThe member path.
opFilterOperatorThe comparison operator.
valueobjectThe 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
filterstringThe filter expression to parse and apply.
optionsQueryStringOptionsOptional query-string parsing options.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Exceptions
- ArgumentNullException
Thrown when
filterisnull.
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
modelExpressionModel<TEntity>The serializable filter model.
serializerExpressionSerializerOptional serializer; the default applies when omitted.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Exceptions
- ArgumentNullException
Thrown when
modelisnull.
Where(ISpecification<TEntity>)
Filters the query using the supplied specification.
public QueryOptions<TEntity> Where(ISpecification<TEntity> specification)
Parameters
specificationISpecification<TEntity>The specification to apply.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Exceptions
- ArgumentNullException
Thrown when
specificationisnull.
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
selectorExpression<Func<TEntity, TMember>>The member selector.
opFilterOperatorThe comparison operator.
valueTMemberThe value to compare against.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Type Parameters
TMemberThe 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
customizeFunc<IQueryable<TEntity>, IQueryable<TEntity>>The transformation to apply.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Exceptions
- ArgumentNullException
Thrown when
customizeisnull.
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
customizeFunc<IQueryable<TEntity>, IQueryable<TEntity>>The transformation to apply.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Exceptions
- ArgumentNullException
Thrown when
customizeisnull.
WithTag(string)
Associates a diagnostic tag with the query.
public QueryOptions<TEntity> WithTag(string tag)
Parameters
tagstringThe tag to associate.
Returns
- QueryOptions<TEntity>
The same QueryOptions<TEntity> instance for chaining.
Exceptions
- ArgumentNullException
Thrown when
tagisnull.