CodeQuery.Postgres 1.0.0-preview.5

This is a prerelease version of CodeQuery.Postgres.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package CodeQuery.Postgres --version 1.0.0-preview.5
                    
NuGet\Install-Package CodeQuery.Postgres -Version 1.0.0-preview.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CodeQuery.Postgres" Version="1.0.0-preview.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodeQuery.Postgres" Version="1.0.0-preview.5" />
                    
Directory.Packages.props
<PackageReference Include="CodeQuery.Postgres" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CodeQuery.Postgres --version 1.0.0-preview.5
                    
#r "nuget: CodeQuery.Postgres, 1.0.0-preview.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CodeQuery.Postgres@1.0.0-preview.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CodeQuery.Postgres&version=1.0.0-preview.5&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CodeQuery.Postgres&version=1.0.0-preview.5&prerelease
                    
Install as a Cake Tool

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

MIT

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.0-preview.16 125 8/31/2026
1.0.0-preview.15 60 8/29/2026
1.0.0-preview.13 62 8/28/2026
1.0.0-preview.12 73 8/27/2026
1.0.0-preview.11 66 8/27/2026
1.0.0-preview.10 75 8/27/2026
1.0.0-preview.9 80 8/25/2026
1.0.0-preview.8 68 8/24/2026
1.0.0-preview.7 154 8/24/2026
1.0.0-preview.6 72 8/22/2026
1.0.0-preview.5 61 8/19/2026
1.0.0-preview.4 70 8/17/2026
1.0.0-preview.3 60 8/17/2026
1.0.0-preview.2 73 8/13/2026
1.0.0-preview.1 74 8/4/2026