CH.Native 1.1.2-prerelease.33

This is a prerelease version of CH.Native.
dotnet add package CH.Native --version 1.1.2-prerelease.33
                    
NuGet\Install-Package CH.Native -Version 1.1.2-prerelease.33
                    
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="CH.Native" Version="1.1.2-prerelease.33" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CH.Native" Version="1.1.2-prerelease.33" />
                    
Directory.Packages.props
<PackageReference Include="CH.Native" />
                    
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 CH.Native --version 1.1.2-prerelease.33
                    
#r "nuget: CH.Native, 1.1.2-prerelease.33"
                    
#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 CH.Native@1.1.2-prerelease.33
                    
#: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=CH.Native&version=1.1.2-prerelease.33&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CH.Native&version=1.1.2-prerelease.33&prerelease
                    
Install as a Cake Tool

CH.Native

A high-performance modern .NET client for ClickHouse using the native binary TCP protocol.

NuGet NuGet Downloads .NET License

Quick Start

dotnet add package CH.Native
await using var connection = new ClickHouseConnection("Host=localhost;Port=9000");
await connection.OpenAsync();

var result = await connection.ExecuteScalarAsync<int>("SELECT 1");
Console.WriteLine(result); // 1

See the Getting Started Guide for more examples, or run samples/CH.Native.Samples.QuickStart for the same flow as a runnable project.

Features

  • Native Binary Protocol - Direct TCP communication on port 9000 for optimal performance
  • Full Async/Await - All operations are async with streaming support
  • ADO.NET Provider - Standard DbConnection implementation with Dapper compatibility
  • Bulk Insert - High-performance batched inserts with typed mapping
  • Compression - LZ4 (default) and Zstd compression support
  • Resilience - Built-in retry policies, circuit breakers, and health checking
  • Load Balancing - Multi-server support with round-robin, random, or first-available strategies
  • TLS/SSL - Secure connections with certificate validation
  • Telemetry - OpenTelemetry-compatible tracing, metrics, and logging
  • Type Safety - Full support for all ClickHouse types with .NET mapping

Supported ClickHouse Types

CH.Native supports the full ClickHouse type system across read, write, and bulk-insert paths. See Data Types for the complete CLR-mapping reference.

Category ClickHouse Types .NET Mapping
Signed integers Int8, Int16, Int32, Int64, Int128, Int256 sbyte, short, int, long, Int128, BigInteger
Unsigned integers UInt8, UInt16, UInt32, UInt64, UInt128, UInt256 byte, ushort, uint, ulong, UInt128, BigInteger
Floating point Float32, Float64, BFloat16 float, double, float
Fixed-point Decimal32(S), Decimal64(S), Decimal128(S), Decimal256(S) decimal (or ClickHouseDecimal for D128/256 wide range)
Boolean Bool bool
Date / Time Date, Date32, DateTime, DateTime('Tz'), DateTime64(P), Time, Time64(P) DateOnly, DateTime, DateTimeOffset, TimeOnly
String String, FixedString(N) string, byte[]
Network / IDs UUID, IPv4, IPv6 Guid, IPAddress
Enums Enum8, Enum16 sbyte, short (or your enum via cast)
Composites Nullable(T), Array(T), Map(K,V), Tuple(...), Nested(...), LowCardinality(T) T?, T[], Dictionary<K,V>, object[], object[][], T (transparent)
Geospatial Point, Ring, LineString, Polygon, MultiLineString, MultiPolygon Point, Point[], Point[][], Point[][][]
Semi-structured JSON, Dynamic, Variant(T0, T1, ...) string / JsonDocument, ClickHouseDynamic, VariantValue<T0, T1> (boxing-free 2-arm) or ClickHouseVariant (boxed N-arm)

All types round-trip through both the read path (ExecuteReaderAsync, QueryStreamAsync<T>) and the bulk-insert path (CreateBulkInserter<T>). Nullable(...) wraps any non-composite type. Composites compose freely (e.g. Array(Nullable(LowCardinality(String)))).

Installation

dotnet add package CH.Native

Basic Usage

Execute a Query

await using var connection = new ClickHouseConnection("Host=localhost;Port=9000");
await connection.OpenAsync();

// Scalar query
var count = await connection.ExecuteScalarAsync<long>("SELECT count() FROM users");

// DDL/DML
await connection.ExecuteNonQueryAsync("CREATE TABLE IF NOT EXISTS users (id UInt32, name String) ENGINE = Memory");

Query with Parameters

var users = await connection.QueryStreamAsync<User>(
    "SELECT * FROM users WHERE age > @minAge",
    new { minAge = 18 }
).ToListAsync();

Typed Results

public class User
{
    public uint Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
}

await foreach (var user in connection.QueryStreamAsync<User>("SELECT * FROM users"))
{
    Console.WriteLine($"{user.Id}: {user.Name}");
}

Bulk Insert

var users = new List<User> { /* ... */ };

await using var inserter = connection.CreateBulkInserter<User>("users");
await inserter.InitAsync();
await inserter.AddRangeAsync(users);
await inserter.CompleteAsync();

ADO.NET / Dapper

// Use CH.Native.Dapper for the fast-path Dapper-shaped API on top of CH.Native.
using CH.Native.Dapper;

await using var connection = new ClickHouseDbConnection("Host=localhost;Port=9000");
await connection.OpenAsync();

// QueryAsync<T> here is CH.Native.Dapper's fast-path extension — routes
// through CH.Native's typed-accessor mapper, no boxing tax.
var users = await connection.QueryAsync<User>("SELECT * FROM users");

For DI scenarios where the connection is typed as IDbConnection, replace using Dapper; with using CH.Native.Dapper; to opt into the fast path automatically. See ADO.NET & Dapper for the full story.

Documentation

Guide Description
Quick Start Get up and running in minutes
Configuration Connection strings, settings, TLS, multi-server
Authentication Password, JWT, SSH key, mTLS, role activation
Connection Pooling ClickHouseDataSource, sizing, observability
Dependency Injection AddClickHouse, keyed services, providers, health checks
Data Types ClickHouse to .NET type mapping reference
Resilience Retry policies, circuit breakers, load balancing
Bulk Insert High-performance data loading
ADO.NET & Dapper Standard provider and ORM integration
LINQ Provider connection.Table<T>(), operators, modifiers
Telemetry Tracing, metrics, and logging
Performance Comparison Full benchmark matrix vs ClickHouse.Driver and Octonica

Samples

End-to-end runnable console projects under samples/. Each picks a flavour by CLI arg, creates a temp table, runs the demo, and drops the table.

Project What it covers
QuickStart Runnable mirror of docs/quickstart.md — open a connection, scalar query, bulk insert, typed read. Start here.
Queries Every read path: scalar, reader, raw rows, typed, LINQ, ADO.NET, Dapper, pooled, resilient, progress, log analytics
Insert Every write path: single, collection, async stream, one-shot bulk, long-lived, dynamic, pooled, cross-database, plain SQL
Hosting ASP.NET host wiring: AddClickHouse, keyed DataSources, all four auth methods (password / JWT / SSH / mTLS) against a docker overlay, credential providers, per-request role activation, health checks, bulk insert

Performance

Three-way comparison against ClickHouse.Driver (HTTP) and Octonica (native TCP). Each row shows time / memory; the best value in each row is bold.

The tables below cover the headline workloads. For the full benchmark matrix — every row-count scaling for reads/inserts, complex queries (GROUP BY / JOIN / WHERE / ORDER BY), compression algorithms (LZ4 / Zstd), connection-establishment latency, and specialised type comparisons (Geo, Variant, JSON) — see docs/performance-comparison.md.

Small queries (latency)

Workload CH.Native ClickHouse.Driver Octonica
SELECT 1 586 μs 978 μs 878 μs
SELECT count(*) FROM <1M> 992 μs 1,408 μs 1,041 μs
SELECT 100 rows 660 μs 1,183 μs 710 μs

Streaming reads — 1M rows

CH.Native ships an opt-in StringMaterialization=Lazy mode that defers UTF-8 string decode until each field is accessed. The "lazy / default" cells below show both modes; the default mode also benefits from the typed-accessor read path.

Workload CH.Native (lazy / default) ClickHouse.Driver Octonica
Stream id only 79 ms / 0.13 MB · 115 ms / 101 MB 262 ms / 195 MB 79 ms / 80 MB
Stream id + name (string) 58 ms / 54 MB · 76 ms / 54 MB 86 ms / 78 MB 73 ms / 91 MB
Materialize to POCO (typed mapper) 181 ms / 171 MB · 192 ms / 171 MB 475 ms / 265 MB 210 ms / 251 MB

Dapper-style API — 1M rows

CH.Native.Dapper provides Dapper-shaped extensions that route through CH.Native's typed-accessor mapper, sidestepping the per-value boxing Dapper's compiled mapper pays. Compared row-for-row against Dapper on top of ClickHouse.Driver:

Workload CH.Native.Dapper Driver + Dapper CH.Native is
QueryStreamAsync<T> (unbuffered) 104 ms / 101 MB 209 ms / 172 MB 2.0× faster, 41% less mem
QueryAsync<T> (buffered) 143 ms / 117 MB 302 ms / 188 MB 2.1× faster, 38% less mem
QueryAsync<T> via IDbConnection (DI) 151 ms / 117 MB 302 ms / 188 MB 2.0× faster, 38% less mem

Bulk insert — 1M rows

Workload CH.Native ClickHouse.Driver Octonica
Bulk insert 1M rows 99 ms / 0.4 MB 929 ms / 97 MB n/a (errored)

Test conditions

  • Apple M5, .NET 10.0, ClickHouse 26.5.1 (Docker image clickhouse/clickhouse-server:latest resolved at run time).
  • Driver: ClickHouse.Driver 1.2.0 (HTTP); Octonica: Octonica.ClickHouseClient 3.1.8 (native TCP).
  • Reproduce with: dotnet run --project benchmarks/CH.Native.Benchmarks -c Release -- large (or dapper, insert, simple).

Requirements

  • .NET 8.0, 9.0, or 10.0
  • ClickHouse server with native protocol enabled (port 9000)

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Submit a pull request

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on CH.Native:

Package Downloads
CH.Native.DependencyInjection

Microsoft.Extensions.DependencyInjection integration for CH.Native. Registers ClickHouseDataSource as a singleton, supports keyed multi-database setups, IConfiguration binding, rotating-credential providers (JWT, SSH key, mTLS cert), and ASP.NET health checks.

CH.Native.Dapper

Dapper integration for CH.Native. Registers type handlers for array-typed parameters (int[], string[], long[], Guid[], etc.) so `new { ids = arr }` binds as a ClickHouse Array(T) on the wire instead of being expanded into a Tuple by Dapper's default list-expansion behaviour.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.2-prerelease.33 59 5/30/2026
1.1.2-prerelease.32 62 5/30/2026
1.1.2-prerelease.31 70 5/20/2026
1.1.2-prerelease.30 60 5/18/2026
1.1.2-prerelease.29 65 5/17/2026
1.1.2-prerelease.28 61 5/17/2026
1.1.2-prerelease.27 56 5/17/2026
1.1.2-prerelease.26 58 5/15/2026
1.1.1 142 5/9/2026
1.1.1-prerelease.25 69 5/9/2026
1.1.1-prerelease.24 81 5/8/2026
1.1.1-prerelease.23 63 5/7/2026
1.1.0 134 5/6/2026
1.1.0-prerelease.22 63 5/6/2026
1.0.1-prerelease.21 62 5/6/2026
1.0.1-prerelease.20 57 5/6/2026
1.0.1-prerelease.19 57 5/5/2026
1.0.1-prerelease.18 66 5/4/2026
1.0.1-prerelease.17 59 5/2/2026
1.0.1-prerelease.15 64 4/26/2026
Loading failed