QueryLens 1.1.0
See the version list below for details.
dotnet add package QueryLens --version 1.1.0
NuGet\Install-Package QueryLens -Version 1.1.0
<PackageReference Include="QueryLens" Version="1.1.0" />
<PackageVersion Include="QueryLens" Version="1.1.0" />
<PackageReference Include="QueryLens" />
paket add QueryLens --version 1.1.0
#r "nuget: QueryLens, 1.1.0"
#:package QueryLens@1.1.0
#addin nuget:?package=QueryLens&version=1.1.0
#tool nuget:?package=QueryLens&version=1.1.0
QueryLens
Validate raw SQL at test time, not runtime.
QueryLens gives hand-written SQL a lightweight validation surface for Dapper, ADO.NET, and query-registry style codebases. In v2, the default experience is intentionally small:
- write a
SqlQuery,SqlInsert,SqlUpdate,SqlDelete,SqlMerge, orSqlStoredProc - optionally set
QueryLens.Dialect - optionally call
QueryLens.LoadDbSchemaFrom(...) - assert
IsValid, inspectErrors,Warnings, orErrorSummary
Quick Start
dotnet add package QueryLens
Level 1: Generic syntax with no setup
var query = new SqlQuery("SELECT name FROM customers LIMIT 10");
Assert.True(query.IsValid);
Level 1 is permissive on purpose. If you do not set a dialect, QueryLens accepts common syntax forms across supported engines and only rejects SQL that is structurally broken.
Level 2: Dialect and version checks
QueryLens.Dialect = DialectProfile.SqlServer2017;
var query = new SqlQuery("SELECT STRING_AGG(name, ',') FROM departments");
Assert.True(query.IsValid);
Once a dialect is set, QueryLens adds stricter checks such as:
- built-in function validation
- version-gated function availability
- reserved-word warnings
- dialect-specific syntax behavior
Level 3: Schema-backed validation
QueryLens.Dialect = DialectProfile.SqlServer2017;
QueryLens.LoadDbSchemaFrom(connectionString);
var query = new SqlQuery("SELECT id, missing_column FROM customers");
Assert.False(query.IsValid);
Assert.Contains(query.Errors, issue => issue.Code == "QL0011");
Schema loading snapshots the database once, then validates against that immutable in-memory snapshot. QueryLens does not hit the database on each validation call.
Core API
QueryLens.Dialect = DialectProfile.SqlServer2019;
QueryLens.LoadDbSchemaFrom(connectionString);
var query = new SqlQuery("SELECT * FROM dbo.orders WHERE order_id = @Id");
var isValid = query.IsValid;
var errors = query.Errors;
var warnings = query.Warnings;
var summary = query.ErrorSummary;
Available facade members:
QueryLens.DialectQueryLens.HasLoadedSchemaQueryLens.IsFrozenQueryLens.LoadDbSchemaFrom(...)QueryLens.LoadDbSchemaFromAsync(...)QueryLens.RefreshDbSchema()QueryLens.ClearDbSchema()QueryLens.Reset()QueryLens.ValidateAssembly(assembly)
Freeze Model
QueryLens uses global immutable runtime snapshots.
- configuration is mutable until first validation
- after first validation, QueryLens freezes
- changing
Dialect, loading schema, refreshing schema, or clearing schema throws untilQueryLens.Reset()
That design keeps cached validation results deterministic and safe under parallel test execution.
Assembly Validation
QueryLens.Dialect = DialectProfile.SqlServer2017;
var result = QueryLens.ValidateAssembly(typeof(OrderQueries).Assembly);
Assert.True(result.AllValid);
This validates every discovered SqlStatement in the target assembly against the active global QueryLens level.
Statement Types
All statement wrappers implicitly convert to string, so they still drop into Dapper naturally.
await connection.QueryAsync<Customer>(
new SqlQuery("SELECT * FROM customers WHERE status = @Status"),
new { Status = "active" });
Supported wrappers:
SqlQuerySqlInsertSqlUpdateSqlDeleteSqlMergeSqlStoredProc
Validation Levels
| Level | Trigger | What it validates |
|---|---|---|
| 1 | Default | Generic SQL structure using a permissive cross-dialect superset |
| 2 | QueryLens.Dialect = ... |
Level 1 plus dialect/version checks |
| 3 | QueryLens.LoadDbSchemaFrom(...) |
Level 2 plus schema object existence and column/proc checks |
Performance Model
QueryLens is designed for test-time validation:
- statement construction is cheap
- parsing is lazy
- parsing happens only when validation is requested
- parsed output is cached
- validation results are cached
- runtime code that never touches validation pays effectively no validation cost
Compatibility
The legacy builder-first APIs are no longer part of the public package surface in v2. The migration story is facade-first, with any remaining builder infrastructure kept internal for friend-assembly tests and transitional implementation only.
For migration guidance, see docs/technical/V2-COMPATIBILITY-GUIDE.md.
Documentation
- Product direction: docs/PRD_v2.md
- Technical spec: docs/SPEC.md
- Interface contracts: docs/technical/INTERFACE-CONTRACTS.md
- Settings deep dive: docs/technical/QUERYLENS-SETTINGS-EXPLAINED.md
- Testing patterns: docs/testing/PATTERNS-BACKEND.md
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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 was computed. 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. |
-
net9.0
- Microsoft.Data.SqlClient (>= 6.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.3 | 741 | 4/12/2026 |
| 1.1.3-preview.40 | 50 | 5/3/2026 |
| 1.1.2 | 97 | 4/12/2026 |
| 1.1.1 | 98 | 4/12/2026 |
| 1.1.0 | 102 | 4/12/2026 |
| 1.0.0 | 126 | 4/11/2026 |
| 1.0.0-preview.10 | 66 | 4/7/2026 |
| 1.0.0-preview.9 | 55 | 4/5/2026 |
| 1.0.0-preview.8 | 66 | 4/5/2026 |
| 1.0.0-preview.7 | 50 | 4/5/2026 |
| 1.0.0-preview.6 | 63 | 4/5/2026 |
| 1.0.0-preview.4 | 57 | 4/4/2026 |
| 1.0.0-preview.3 | 73 | 4/4/2026 |
| 1.0.0-preview.1 | 60 | 4/2/2026 |
v1.1.0: PostgreSQL 15–17 dialect support — version-gated syntax, 20+ new built-in functions, MERGE command, enum type mapping, reserved word updates, and 6 parser false-positive fixes with regression test suite (29 tests, 26 ACs).