End-User Documentation

Use QueryLens with Dapper

Use QueryLens with Dapper

QueryLens is designed to fit Dapper naturally because statement wrappers implicitly convert to string and do not change your runtime execution path.

Practical Pattern

  • Keep QueryLens validation in tests, fixtures, or build-time checks rather than in production request paths.
  • Use wrappers close to the SQL definition so the validated text is the same text Dapper executes.
  • Pair validation parameters with the same anonymous object shape you expect Dapper to receive.

Example

var sql = new SqlQuery(
    "SELECT * FROM dbo.customers WHERE status = @Status",
    validationParameters: new { Status = "active" });

Assert.True(sql.IsValid);

var rows = await connection.QueryAsync<Customer>(sql, new { Status = "active" });

Related