public sealed class RunicQueryFields<TRow> The fields a page may sort and filter a RunicQuery by, and how each maps to a LINQ expression of the row. RunicQueryFields.Apply turns a query into Where and OrderBy calls, so an Entity Framework Core or other LINQ provider runs it in the database.
Type parameters
TRowThe row type of the
IQueryable.
Remarks
Only registered fields can be used: a query that names another field, or uses an operator a field does not support, fails RunicQueryFields.Validate with ArgumentException, which the page receives as invalid-input. Register fields under the names the page uses, normally the rows' wire names.
A field accepts RunicFilterOperator.Equal for any supported value type, RunicFilterOperator.Range for types with comparison operators (numbers, dates and times, TimeSpan), and RunicFilterOperator.Contains when it is registered with RunicQueryFields.AddText. Values are read from JSON as the field's type: strings, Booleans, integers, floating-point and decimal numbers, Guid, DateTime, DateTimeOffset, DateOnly, TimeOnly, TimeSpan (ISO 8601 or c format) and enums (by name or number).
Constructors
RunicQueryFields
public RunicQueryFields() No documentation.
Methods
Add
public RunicQueryFields<TRow> Add<TValue>(string name, Expression<Func<TRow, TValue>> selector) Registers a field that can be sorted by and filtered with equality and, where the type allows, ranges.
Type parameters
TValueThe field's type.
Parameters
nameThe field name the page uses.
selectorThe field of a row, such as
row => row.Created.
Returns
This instance.
AddCustom
public RunicQueryFields<TRow> AddCustom(string name, Func<IQueryable<TRow>, JsonElement, IQueryable<TRow>> apply) Registers a RunicFilterOperator.Custom filter, the escape hatch for filters the typed model lacks.
Parameters
nameThe filter's name.
applyApplies the filter with its JSON argument (
JsonValueKind.Undefinedwhen the page sent none). The argument is untrusted JSON from the page: read only what the filter expects, and throwArgumentExceptionfor anything else.RunicQueryFields.Validateruns the filter once over no rows, so an argument it rejects isinvalid-inputwhen the page sets the query.
Returns
This instance.
AddText
public RunicQueryFields<TRow> AddText(string name, Expression<Func<TRow, string?>> selector, bool ignoreCase = true) Registers a text field, which also supports RunicFilterOperator.Contains.
Parameters
nameThe field name the page uses.
selectorThe text of a row.
ignoreCaseWhether
containsignores case, by comparingString.ToLowerof both, which database providers translate. Otherwise the provider's own comparison applies.
Returns
This instance.
Apply
public IOrderedQueryable<TRow> Apply<TKey>(IQueryable<TRow> rows, RunicQuery query, Expression<Func<TRow, TKey>> key) Filters and orders rows: RunicQueryFields.Filter, then RunicQueryFields.Sort.
Type parameters
TKeyThe row key.
Parameters
rowsThe rows.
queryThe query.
keyThe row key, the last sort key.
Returns
The filtered, ordered rows.
Filter
public IQueryable<TRow> Filter(IQueryable<TRow> rows, RunicQuery query) Applies query's filters to rows.
Parameters
rowsThe rows.
queryThe query.
Returns
The filtered rows.
Exceptions
ArgumentExceptionThe query names an unknown field, or a value does not read as the field's type.
Sort
public IOrderedQueryable<TRow> Sort<TKey>(IQueryable<TRow> rows, RunicQuery query, Expression<Func<TRow, TKey>> key) Orders rows by query's sort keys, then by key, so that ranges of the result are stable.
Type parameters
TKeyThe row key.
Parameters
rowsThe rows.
queryThe query.
keyThe row key, the last sort key.
Returns
The ordered rows.
Validate
public void Validate(RunicQuery query) Checks that every sort key and filter of query names a field that supports it.
Parameters
queryThe query.
Exceptions
ArgumentExceptionThe query names an unknown field, or a value does not read as the field's type.