QueryLens 1.1.1
See the version list below for details.
dotnet add package QueryLens --version 1.1.1
NuGet\Install-Package QueryLens -Version 1.1.1
<PackageReference Include="QueryLens" Version="1.1.1" />
<PackageVersion Include="QueryLens" Version="1.1.1" />
<PackageReference Include="QueryLens" />
paket add QueryLens --version 1.1.1
#r "nuget: QueryLens, 1.1.1"
#:package QueryLens@1.1.1
#addin nuget:?package=QueryLens&version=1.1.1
#tool nuget:?package=QueryLens&version=1.1.1
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:
- wrap each statement in
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
Mark your SQL constants with the appropriate attribute, then validate the whole assembly in a single assertion.
public static class OrderQueries
{
[SqlQuery]
public static readonly string GetById = "SELECT id, total FROM orders WHERE id = @Id";
[SqlInsert]
public static readonly string Create = "INSERT INTO orders (id, total) VALUES (@Id, @Total)";
[SqlUpdate]
public static readonly string UpdateTotal = "UPDATE orders SET total = @Total WHERE id = @Id";
[SqlDelete]
public static readonly string Remove = "DELETE FROM orders WHERE id = @Id";
}
Then in your test project:
QueryLens.Dialect = DialectProfile.SqlServer2017;
var result = QueryLens.ValidateAssembly(typeof(OrderQueries).Assembly);
Assert.True(result.AllValid);
ValidateAssembly discovers every field, property, and method decorated with a [SqlQuery], [SqlInsert], [SqlUpdate], [SqlDelete], [SqlMerge], or [SqlStoredProc] attribute and validates each one against the active 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
Documentation
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 | 742 | 4/12/2026 |
| 1.1.3-preview.40 | 50 | 5/3/2026 |
| 1.1.2 | 98 | 4/12/2026 |
| 1.1.1 | 99 | 4/12/2026 |
| 1.1.0 | 103 | 4/12/2026 |
| 1.0.0 | 127 | 4/11/2026 |
| 1.0.0-preview.10 | 67 | 4/7/2026 |
| 1.0.0-preview.9 | 56 | 4/5/2026 |
| 1.0.0-preview.8 | 67 | 4/5/2026 |
| 1.0.0-preview.7 | 51 | 4/5/2026 |
| 1.0.0-preview.6 | 64 | 4/5/2026 |
| 1.0.0-preview.4 | 58 | 4/4/2026 |
| 1.0.0-preview.3 | 74 | 4/4/2026 |
| 1.0.0-preview.1 | 61 | 4/2/2026 |
v1.1.1: README fixes — added [SqlQuery]/[SqlInsert] attribute usage examples for assembly validation, fixed broken documentation links, removed confusing internal version references.