Lyo.Query.Models
2.0.0
dotnet add package Lyo.Query.Models --version 2.0.0
NuGet\Install-Package Lyo.Query.Models -Version 2.0.0
<PackageReference Include="Lyo.Query.Models" Version="2.0.0" />
<PackageVersion Include="Lyo.Query.Models" Version="2.0.0" />
<PackageReference Include="Lyo.Query.Models" />
paket add Lyo.Query.Models --version 2.0.0
#r "nuget: Lyo.Query.Models, 2.0.0"
#:package Lyo.Query.Models@2.0.0
#addin nuget:?package=Lyo.Query.Models&version=2.0.0
#tool nuget:?package=Lyo.Query.Models&version=2.0.0
Lyo.Query.Models
Filter / sort / projection DTOs and fluent builders for query requests. Lyo.Query consumes the same WhereClause tree (turns it into LINQ on IQueryable) and Lyo.Api endpoints (QueryConcrete, QueryProject, root Query) do too, so HTTP clients and in-process tests build queries the same way.
Covers the polymorphic where-clause AST, QueryConcreteReq / ProjectionQueryReq / QueryReq, sort + explain result shapes, and builders (WhereClauseBuilder, QueryConcreteReqBuilder, ProjectionQueryReqBuilder, QueryReqBuilder).
Caching. Result caching for
POST …/QueryConcreteandPOST …/QueryProjectis configured > on the API host (QueryOptions.CacheQueryResultsAsUtf8Payload,ICacheService/ Fusion), > not on these DTOs. See Query result caching in the Lyo.Api README.
Targets netstandard2.0;net10.0. Depends on Lyo.Exceptions, Lyo.Common.Core, and Lyo.Result.
Features
- WhereClause AST. Polymorphic
condition/groupJSON tree, with optionalSubClausefor two-phase filters. - QueryConcreteReq. Entity-graph body for
POST …/QueryConcrete(includes, sort, keys, options). - ProjectionQueryReq.
Selectplus computed fields forPOST …/QueryProject. - QueryReq (root).
From/Joins/Selectfor dynamic-contextPOST …/Query. - Builders.
WhereClauseBuilder,QueryConcreteReqBuilder,ProjectionQueryReqBuilder,QueryReqBuilder. - ParameterOptions. Static key/label list, a root
QueryReqtemplate, or aschema.funcsproc (StoredProcName,SprocParameterswith{{Key}}placeholders) for Job/Reporting definition parameter pickers (ParameterOptionsJson,ParameterOptionsBinder,ParameterOptionsResolveReq). - Shared with Lyo.Query + Lyo.Api. The same DTOs for in-process LINQ and HTTP endpoints.
- Explain → errors.
WhereClauseExplainResult.ToErrorsmaps a failed in-memory explain tree toLyo.Result.Error(AND = per-leaf, OR = one summary). Used by validation schemas, not for SQLApplyWhereClause. - Parameter validation (
Parameters/).LyoParameterSpec/LyoParameterValueSpecare the backend-neutral projections of a parameter definition and a supplied value (From(ILyoParameterDefinition)/From(ILyoParameterValue)), andLyoParameterValidatoris the single validator over them. Job, Reporting, and Config all delegate here instead of each carrying their own copy of the required / regex / length / allowed-values rules.
Examples
WhereClauseBuilder
// Simple conditions
var node = WhereClauseBuilder.And()
.Equals("Status", "Active")
.GreaterThan("Age", 18)
.Build();
// Nested AND/OR
var node = WhereClauseBuilder.And()
.AddOr(or => or.Equals("Status", "Active").Equals("Status", "Pending"))
.AddAnd(and => and.Contains("Tags", "verified").In("Region", "US", "CA"))
.Build();
// Explicit grouped node (same as AddAnd/AddOr, but useful for clarity)
var grouped = WhereClauseBuilder.And()
.AddGroupOr(g => g.Equals("Region", "US").Equals("Region", "CA"))
.Build();
QueryConcreteReqBuilder
using Lyo.Query.Models.Builders;
using Lyo.Query.Models.Enums;
var query = QueryConcreteReqBuilder.New()
.AddIncludes("Addresses", "PhoneNumbers")
.AddWhere(b => b
.Equals("Status", "Active")
.AddAnd(inner => inner
.GreaterThan("Age", 18)
.Contains("Tags", "verified")))
.AddSort("CreatedAt", SortDirection.Desc)
.SetPagination(0, 20)
.Build();
// Typed via For<T>()
var typed = QueryConcreteReqBuilder.New()
.For<Person>()
.Include(p => p.Addresses)
.AddWhere(q => q.AddEquals(p => p.Status, "Active"))
.Done()
.Build();
Build a root /Query with QueryReqBuilder
var query = QueryReqBuilder.New()
.From("o", "OrderEntity")
.Join("p", "PersonEntity", JoinType.Left, on => {
on.Add(new JoinOn { From = "o.PersonId", To = "p.Id" });
}, asName: "recipient")
.AddSelects("o.Id", "p.FirstName", "p.LastName")
.SetPagination(0, 50)
.Build();
// POST /api/Job/Query
Two-phase SubClause
var node = WhereClauseBuilder.And()
.Equals("Age", 10)
.AddSubClause(sub => sub.AddAnd(s => s.Equals("Name", "Alice")))
.Build();
ProjectionQueryReqBuilder
using Lyo.Query.Models.Builders;
using Lyo.Query.Models.Enums;
var query = ProjectionQueryReqBuilder.New()
.AddSelects("Id", "Name", "Email")
.AddWhere(b => b.Equals("Status", "Active"))
.AddComputedField("Label", "{Name} — {Email}")
.SetZipSiblingCollectionSelections(true)
.SetPagination(0, 20)
.Build();
// POST {baseRoute}/QueryProject
Benchmarks
- Portfolio suite:
query
Where-clause tree
| Type | Role |
|---|---|
WhereClause (abstract) |
Root of the polymorphic filter tree. [JsonDerivedType] discriminators are condition / group. Carries optional Description and SubClause (two-phase filter chain). |
ConditionClause |
Leaf: dotted Field, Comparison (ComparisonOperatorEnum), and Value (scalar, list, or CSV string for In / NotIn). Implements IEquatable<ConditionClause> and Print(indent). |
GroupClause |
Branch: Operator (GroupOperatorEnum) + List<WhereClause> Children; structural Equals / GetHashCode and Print(indent). |
Polymorphic JSON shape produced by System.Text.Json:
{
"$type": "group",
"operator": "And",
"children": [
{ "$type": "condition", "field": "Status", "comparison": "Equals", "value": "Open" },
{ "$type": "condition", "field": "Lines.Quantity", "comparison": "GreaterThan", "value": 0 }
]
}
JSON property names match the C# property names under the default camelCase policy
(condition/group come from [JsonDerivedType]); the model classes do not use
[JsonPropertyName].
Enums
ComparisonOperatorEnum.Unknown,Equals,NotEquals,Contains,NotContains,StartsWith,EndsWith,NotStartsWith,NotEndsWith,GreaterThan,GreaterThanOrEqual,LessThan,LessThanOrEqual,In,NotIn,Regex,NotRegex. Each carries a[Description]symbol (=,≠, etc.) for UI use.GreaterThan*/LessThan*over collection navigations operate on the collection's count.GroupOperatorEnum.And,Or.QueryTotalCountMode.Exact,None,HasMore.QueryIncludeFilterMode.Full,MatchedOnly.JoinType.Inner,Left(root/Queryjoins; v1).
Request DTOs under Common/Request
QueryRequestBase. Shared fields:Start,Amount(paging),Keys. Polymorphic JSON ($type:concrete/project/root) so cache/API can deserializeProjectedQueryRes.QueryRequest(List<object[]>of composite primary keys),WhereClause,Include(navigation paths for eager load),SortBy(List<SortBy>).QueryConcreteReq : QueryRequestBase, IQueryExecutionRequest. Request body for/QueryConcrete(entity graphs).Options : QueryRequestOptions(TotalCount + IncludeFilter).ProjectionQueryReq : QueryRequestBase, IQueryExecutionRequest. Request body for/QueryProject. AddsSelect(required) andComputedField[] ComputedFields.Includeis ignored. Navigations are derived fromSelectand any collection paths referenced inWhereClause.Options : ProjectedQueryRequestOptionsaddsZipSiblingCollectionSelections(defaulttrue).QueryReq : QueryRequestBase, IQueryExecutionRequest. Request body for root/Query(dynamic context base). RequiredFrom(FromClause), optionalJoins(JoinClause), requiredSelect(alias.property), optionalComputedFields.Includeforbidden. NestedFromClause.Query/JoinClause.Queryis aSourceQueryScope(Where/Keys), notWhereClause.SubClause.FromClause/JoinClause/JoinOn/SourceQueryScope. Join AST for root Query.ComputedField(Name, Template). Adds a column derived from a SmartFormat template evaluated against the projected row (requiresIFormatterServicein the host).IQueryExecutionRequest. Shared methods for concrete / projection / root query.
Maps onto Lyo.Api host routes (see Lyo.Api for caching, options, and SQL projection details):
| Request DTO | Endpoint | Response |
|---|---|---|
QueryConcreteReq |
POST {baseRoute}/QueryConcrete |
QueryRes<T> (entity graphs) |
ProjectionQueryReq |
POST {baseRoute}/QueryProject |
ProjectedQueryRes<T> |
QueryReq |
POST {dynamicBase}/Query |
ProjectedQueryRes (JSON rows; From/Joins) |
Result caching for QueryConcrete / QueryProject is host-side (QueryOptions.CacheQueryResultsAsUtf8Payload + ICacheService / Fusion), not on these DTOs. Both endpoints share the same option and tag-based invalidation (QueryCacheKeyBuilder / QueryCacheTagBuilder).
Sort
SortBy(PropertyName, Direction?, Priority?). Dotted property path with an optional explicitPriority. When omitted, list order in the request determines tie-break order.
Explain results
WhereClauseExplainResult, WhereClauseExplainNode, WhereClauseExplainKind, and ExplainOrBranchOutcome come from IWhereClauseService.ExplainMatch<TEntity>(...) in Lyo.Query. Each node tracks Passed, AST Path, optional Description, group Operator, condition Field / Comparison / FilterValue / ActualValueSummary, and SubClause chains. The top-level result also carries BlockingPath, FailureSummary, and per-branch detail for failed Or groups.
Builders
| Builder | Produces | Notes |
|---|---|---|
WhereClauseBuilder |
WhereClause |
And() / Or(); per-operator helpers (Equals, Contains, In, Regex, …); nested groups; AddSubClause / AddConditionWithSubClause for two-phase filters |
WhereClauseBuilderFor<T> |
WhereClause |
From WhereClauseBuilder.For<T>(). Property paths via Expression<Func<T, …>> |
QueryConcreteReqBuilder |
QueryConcreteReq |
Includes, keys, where, sort, paging, total-count / include-filter modes; For<T>() typed helpers |
ProjectionQueryReqBuilder |
ProjectionQueryReq |
Same as concrete plus AddSelect / AddComputedField / zip sibling collections |
QueryReqBuilder |
QueryReq |
Root /Query: From, Join, selects, where/sort/paging |
See Examples above for builder samples (also documented under Query & Request Builders in Lyo.Api).
Attributes plus exceptions
[QueryPropertyName("CanonicalName")]. Overrides the serialized / query path name when the C# property differs from the canonical query path (useful when EF scaffolding or DTOs rename a column).InvalidQueryException : InvalidOperationException. Thrown byLyo.Queryfor invalid paths or unsupported operators.
Parameter validation (Parameters/)
LyoParameterValidator holds the rules that Job, Reporting, and Config parameters share:
| Member | Role |
|---|---|
Validate(specs, values) |
Returns the human-readable error list for a set of supplied values against their definitions: missing required parameters, unknown keys, regex mismatches, length bounds, and allowed-value membership. Empty list means valid. |
ValidateSpec(spec, errors) |
Validates a definition itself — that its own regex compiles, its bounds are coherent, and its allowed-values list is usable. Used on write paths so a bad definition is rejected at save time rather than at run time. |
ValidateUniqueKeys(specs, errors) |
Rejects duplicate parameter keys within one definition set. |
MaxValidationRegexLength (500) / RegexMatchTimeout (1s) |
Guardrails against catastrophic backtracking from user-supplied ValidationRegex values. |
Values carrying an encrypted payload satisfy a required check without the plaintext being present (LyoParameterValueSpec.HasEncryptedValue).
Type checking accepts both storage conventions in the tree: Reporting persists JSON-encoded values, Job persists what the user typed. A scalar that is not valid JSON gets a second chance as a JSON string literal, so 2026-01-01 passes as a DateTime. Structured types (JSON objects and arrays, collections, XML, formatter templates) get no such leniency — quoting a malformed payload would turn it into a valid string and hide the error.
Dependencies
Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).
Lyo.Common.Core(direct, lyo)Lyo.Common.Json(direct, lyo)Lyo.Exceptions(direct, lyo)Lyo.Parameters(direct, lyo)Lyo.Common.Metadata(transitive, lyo)Microsoft.Bcl.AsyncInterfaces10.0.5(transitive, microsoft, netstandard2.0)System.Memory4.6.3(transitive, microsoft, netstandard2.0)System.Text.Json10.0.5(transitive, microsoft, netstandard2.0)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Lyo.Common.Json (>= 2.0.0)
- Lyo.Exceptions (>= 2.0.0)
- Lyo.Parameters (>= 2.0.0)
-
net10.0
- Lyo.Common.Json (>= 2.0.0)
- Lyo.Exceptions (>= 2.0.0)
- Lyo.Parameters (>= 2.0.0)
NuGet packages (18)
Showing the top 5 NuGet packages that depend on Lyo.Query.Models:
| Package | Downloads |
|---|---|
|
Lyo.Api.Models
API models and data transfer objects for the Lyo API library suite. |
|
|
Lyo.Api.Client
API client library for consuming Lyo APIs. |
|
|
Lyo.Validation
Reusable validators and a fluent builder for validating strongly typed models with structured Result-based failures. |
|
|
Lyo.Query
Query filtering and property comparison services for IQueryable. Uses Lyo.Query.Models for query types. |
|
|
Lyo.Web.Components
Blazor components library for the Lyo web UI framework with MudBlazor integration. |
GitHub repositories
This package is not used by any popular GitHub repositories.