CodeQuery 1.0.0-preview.3
See the version list below for details.
dotnet add package CodeQuery --version 1.0.0-preview.3
NuGet\Install-Package CodeQuery -Version 1.0.0-preview.3
<PackageReference Include="CodeQuery" Version="1.0.0-preview.3" />
<PackageVersion Include="CodeQuery" Version="1.0.0-preview.3" />
<PackageReference Include="CodeQuery" />
paket add CodeQuery --version 1.0.0-preview.3
#r "nuget: CodeQuery, 1.0.0-preview.3"
#:package CodeQuery@1.0.0-preview.3
#addin nuget:?package=CodeQuery&version=1.0.0-preview.3&prerelease
#tool nuget:?package=CodeQuery&version=1.0.0-preview.3&prerelease
CodeQuery
Write type-safe, robust SQL in C#. The bridge between SQL and C#.
CodeQuery is a .NET Standard 2.1 library for expressing queries, schema, migrations and routines through the C# type system. It stays as close to SQL as possible while letting the compiler check every column and table reference — so a rename refactors your queries instead of breaking them at runtime.
Install
Add the core package and the driver for your database:
dotnet add package CodeQuery
dotnet add package CodeQuery.Sqlite # or CodeQuery.Postgres / CodeQuery.MySql / CodeQuery.Mssql
| Package | Database |
|---|---|
CodeQuery |
Core library (required) |
CodeQuery.Postgres |
PostgreSQL, over Npgsql |
CodeQuery.Sqlite |
SQLite, over Microsoft.Data.Sqlite |
CodeQuery.MySql |
MySQL and MariaDB, over MySqlConnector |
CodeQuery.Mssql |
Microsoft SQL Server, over System.Data.SqlClient |
CodeQuery.Postgres.PostGis |
PostGIS spatial types and functions |
CodeQuery.Postgres.Timescale |
TimescaleDB hypertables, policies, continuous aggregates and hyperfunctions |
CodeQuery.EntityFramework |
Query the tables an existing EF Core DbContext already maps |
Define a schema
Declare your database as a class — one member per database object, each member constructing itself — and let CodeQuery inspect the entity types:
public class AppDb : IDbSchema
{
// tables — the shape comes from the entity type, the rest travels with the member
public DbTable<Author> Authors => new();
public DbTable<Book> Books => new(b => b.Column(x => x.Price).Check(p => p >= 0));
// views, stored procedures and functions are the objects you hand back, nothing inferred
public DbView<ExpensiveBook> Expensive => new ExpensiveBooksView();
}
var db = DatabaseInitializer.Build<AppDb>(configuration);
Query
var books = db.From<Book>()
.InnerJoin(Author.On(), b => b.AuthorId)
.Select((b, a) => new { b.Title, a.Name })
.Fetch();
The property references are compiler-checked and refactor-safe — there are no SQL strings in the query.
Strong typing
Strong typing is the core principle. Schema constraints, defaults and partition bounds are expressed as typed CLR values and expression trees, never as SQL fragments:
// The check is an expression; the compiler validates the column and the comparison.
productTable.HasCheck("CK_Products_Price", r => r.Price >= 0);
// The partition key is an expression; the range bounds follow the key's type.
config.PartitionBy(s => s.LogDate)
.AsRange()
.Add("y2024", new DateTime(2024, 1, 1), new DateTime(2025, 1, 1));
Documentation
Full guides — queries, joins, aggregates, CTEs, window functions, migrations, views, stored
procedures, full-text search and dialect support — live in the Web/ documentation site.
License
| 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 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | 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.1
- System.ComponentModel.Annotations (>= 5.0.0)
- System.Runtime.Loader (>= 4.3.0)
- System.Text.Json (>= 9.0.9)
- YamlDotNet (>= 18.1.0)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on CodeQuery:
| Package | Downloads |
|---|---|
|
CodeQuery.Postgres
PostgreSQL driver for CodeQuery. Renders CodeQuery's type-safe queries, schema and migrations to PostgreSQL dialect SQL and executes them over Npgsql. |
|
|
CodeQuery.Mssql
Microsoft SQL Server driver for CodeQuery. Renders CodeQuery's type-safe queries, schema and migrations to T-SQL and executes them over System.Data.SqlClient. |
|
|
CodeQuery.MySql
MySQL and MariaDB driver for CodeQuery. Renders CodeQuery's type-safe queries, schema and migrations to MySQL dialect SQL and executes them over MySqlConnector. |
|
|
CodeQuery.Sqlite
SQLite driver for CodeQuery. Renders CodeQuery's type-safe queries, schema and migrations to SQLite dialect SQL and executes them over Microsoft.Data.Sqlite. |
|
|
CodeQuery.EntityFramework
Builds CodeQuery query sources from an existing Entity Framework Core DbContext. The table name, schema and column mapping are read from the EF model, so there is no second schema to maintain: DbSet<T>.ToCodeQuery() hands back a DbTable<T> you can query with CodeQuery's type-safe SQL surface. Reads the EF model only — it scaffolds no migrations and owns no schema. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-preview.16 | 126 | 8/31/2026 |
| 1.0.0-preview.15 | 69 | 8/29/2026 |
| 1.0.0-preview.13 | 67 | 8/28/2026 |
| 1.0.0-preview.12 | 79 | 8/27/2026 |
| 1.0.0-preview.11 | 68 | 8/27/2026 |
| 1.0.0-preview.10 | 68 | 8/27/2026 |
| 1.0.0-preview.9 | 82 | 8/25/2026 |
| 1.0.0-preview.8 | 67 | 8/24/2026 |
| 1.0.0-preview.7 | 158 | 8/24/2026 |
| 1.0.0-preview.6 | 80 | 8/22/2026 |
| 1.0.0-preview.5 | 68 | 8/19/2026 |
| 1.0.0-preview.4 | 77 | 8/17/2026 |
| 1.0.0-preview.3 | 65 | 8/17/2026 |
| 1.0.0-preview.2 | 83 | 8/13/2026 |
| 1.0.0-preview.1 | 92 | 8/4/2026 |