Skip to content
ParticleDB
Release candidateParticleDB 1.1.19-rc.17 is not yet GA or ready for production data.Release status →

C# / .NET

Use the configured address for your client. See connection addresses and security. The examples use the SQL client address unless they explicitly select the HTTP API or ParticleDB JDBC driver.

A native ParticleDB package for .NET is not published yet. Use Npgsql over the SQL client interface (port 5432).

Terminal window
dotnet add package Npgsql

Add Server Compatibility Mode=NoTypeLoading to the connection string. Without it, opening the first connection fails while Npgsql loads type information, with 42883: operator does not exist: integer = text.

The example connects as postgres with the password secret, for a server started with particledb start --auth-method scram-sha-256 --pg-password secret. With the server’s default --auth-method password, add SSL Mode=Require; see TLS and authentication.

using Npgsql;
var connStr = "Host=localhost;Port=5432;Username=postgres;Password=secret;" +
"Database=particledb;Server Compatibility Mode=NoTypeLoading";
await using var dataSource = NpgsqlDataSource.Create(connStr);
await using (var cmd = dataSource.CreateCommand(
"CREATE TABLE users (id BIGINT PRIMARY KEY, name TEXT)"))
{
await cmd.ExecuteNonQueryAsync();
}
await using (var cmd = dataSource.CreateCommand(
"INSERT INTO users (id, name) VALUES ($1, $2)"))
{
cmd.Parameters.Add(new NpgsqlParameter { Value = 1L });
cmd.Parameters.Add(new NpgsqlParameter { Value = "Alice" });
Console.WriteLine(await cmd.ExecuteNonQueryAsync()); // 1
}
// Transaction
await using (var conn = await dataSource.OpenConnectionAsync())
await using (var tx = await conn.BeginTransactionAsync())
{
await using var cmd = new NpgsqlCommand(
"INSERT INTO users (id, name) VALUES ($1, $2)", conn, tx);
cmd.Parameters.Add(new NpgsqlParameter { Value = 2L });
cmd.Parameters.Add(new NpgsqlParameter { Value = "Bob" });
await cmd.ExecuteNonQueryAsync();
await tx.CommitAsync();
}
await using (var cmd = dataSource.CreateCommand(
"SELECT id, name FROM users WHERE id >= $1 ORDER BY id"))
{
cmd.Parameters.Add(new NpgsqlParameter { Value = 1L });
await using var reader = await cmd.ExecuteReaderAsync();
while (await reader.ReadAsync())
Console.WriteLine($"{reader.GetInt64(0)} {reader.GetString(1)}");
}

Output:

1
1 Alice
2 Bob

Key-value operations and vector search are SQL, so you run them with NpgsqlCommand like any other statement, for example SELECT KV_GET($1). See Vector Search.