Skip to content

Mise Setup

SteffenBlake edited this page Sep 28, 2026 · 1 revision

Database setup

Mise uses a database runtime for SQL syntax and connections, plus a matching engine package for generated mappings and SQL diagnostics. Install them in the project that contains your table and row declarations.

Choose a database

Database Runtime package Engine package Namespace
SQL Server Brigade.Net.Mise.SqlServer Brigade.Net.Mise.Engines.SqlServer Brigade.Net.Mise.SqlServer
PostgreSQL Brigade.Net.Mise.PostgreSQL Brigade.Net.Mise.Engines.PostgreSQL Brigade.Net.Mise.PostgreSQL
SQLite Brigade.Net.Mise.SQLite Brigade.Net.Mise.Engines.SQLite Brigade.Net.Mise.SQLite
MySQL Brigade.Net.Mise.MySQL Brigade.Net.Mise.Engines.MySQL Brigade.Net.Mise.MySQL
MariaDB Brigade.Net.Mise.MariaDb Brigade.Net.Mise.Engines.MariaDb Brigade.Net.Mise.MariaDb

For PostgreSQL:

dotnet add package Brigade.Net.Mise
dotnet add package Brigade.Net.Mise.PostgreSQL
dotnet add package Brigade.Net.Mise.Engines.PostgreSQL

The runtime includes its ADO.NET provider. The engine generates table references, relationship fragments, and row materialization. Use one engine per mapped type, and the same engine for related tables.

Supply connection settings

For direct use, implement IDbConfig with a connection string and provider factory:

// CourseDatabaseConfig.cs
public sealed record CourseDatabaseConfig(
    string ConnectionString,
    DbProviderFactory ProviderFactory
) : IDbConfig;

IDbConfig is in Brigade.Net.Mise; DbProviderFactory is in System.Data.Common. Create the configuration with your chosen provider:

var config = new CourseDatabaseConfig(connectionString, NpgsqlFactory.Instance);

await using var reader = new DbReader(config: config);

NpgsqlFactory is in Npgsql. A reader created from configuration opens a connection when its first operation needs one and disposes that connection when the reader is disposed.

For SQL Server, use Microsoft.Data.SqlClient.SqlClientFactory.Instance; for SQLite, use Microsoft.Data.Sqlite.SqliteFactory.Instance. MySQL and MariaDB use MySqlConnector.MySqlConnectorFactory.Instance.

Supply an existing connection

await using var connection = new NpgsqlConnection(connectionString);
await using var reader = new DbReader(connection: connection);

The reader opens the connection if needed, but the connection remains caller-owned. Dispose the reader before the connection. Supply exactly one of config and connection.

Use DbWriter for write commands. Its transaction behavior is explicit when used directly; see Transactions and Resource lifetimes.

Use Mise with Partie

Partie Providers can supply DbReader to queries and DbWriter to commands. The shared integration package is Brigade.Net.Partie.Extensions.Mise; database-specific integration packages add the provider factory and named configuration bundle.

See Mise in ASP.NET Core for named connection strings, bundle registration, and complete handlers. Core SQL building and mapping work with or without Partie.

Clone this wiki locally