Configuring Document Storage
The StoreOptions class is the central configuration object for Polecat. It controls connection settings, schema management, serialization, and more.
Connection String
var store = DocumentStore.For(opts =>
{
opts.Connection("Server=localhost;Database=myapp;User Id=sa;Password=YourStrong!Password;TrustServerCertificate=True");
});Schema Name
By default, Polecat uses the dbo schema. You can change this:
opts.DatabaseSchemaName = "myschema";Auto-Create Schema Objects
Control how Polecat manages database schema:
// Default: CreateOrUpdate - auto-creates and updates tables
opts.AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate;
// CreateOnly - only creates new tables, never modifies existing ones
opts.AutoCreateSchemaObjects = AutoCreate.CreateOnly;
// None - never creates or modifies schema objects
opts.AutoCreateSchemaObjects = AutoCreate.None;WARNING
In production environments, consider setting AutoCreate.None and managing schema migrations separately: dotnet run -- db-apply or dotnet run -- resources setup as a deployment step, or db-patch scripts for a DBA, with db-assert as the gate. See Schema Migrations.
Table Prefix
All Polecat tables use the pc_ prefix:
pc_events-- Event logpc_streams-- Stream metadatapc_event_progression-- Async daemon progressionpc_hilo-- HiLo sequence storagepc_doc_{typename}-- Document tables
Native JSON Column Type
By default, Polecat uses SQL Server 2025's native json data type for document bodies, event data, and headers. To fall back to nvarchar(max) for pre-2025 SQL Server instances:
opts.UseNativeJsonType = false;See JSON Serialization for more details.
Store Policies
Apply policies across all document types:
opts.Policies.AllDocumentsSoftDeleted();
opts.Policies.ForDocument<Order>(mapping =>
{
mapping.DeleteStyle = DeleteStyle.SoftDelete;
});Listeners
Register global session listeners:
opts.Listeners.Add(new MySessionListener());See Session Listeners for more details.
Logging
Configure store-level logging:
opts.Logger(new MyPolecatLogger());HiLo Sequence Defaults
Configure default HiLo sequence settings for numeric identity generation:
opts.HiloSequenceDefaults.MaxLo = 500; // default is 1000Initial Data Seeding
Register data to be seeded on application startup:
opts.InitialData.Add(async (store, ct) =>
{
await using var session = store.LightweightSession();
session.Store(new User { FirstName = "Admin", LastName = "User" });
await session.SaveChangesAsync(ct);
});See Initial Baseline Data for more details.
Translating Database Errors into Your Own Exceptions
If SQL you queue yourself raises errors of its own, such as a guard queued with QueueSqlCommand that refuses a write with THROW, register a transform so your callers receive a typed exception instead of picking through a SqlException:
var store = DocumentStore.For(opts =>
{
opts.ConnectionString = connectionString;
opts.ExceptionTransforms.IfExceptionIs<SqlException>()
.If(e => e.Number == 51000)
.ThenTransformTo(e => new GuardRefusedException(e));
});Your transforms are consulted for what SaveChangesAsync sends, and for what the async daemon sends when it flushes a batch, after the failing operation's own translation and before Polecat's other ones. An error none of them claims is reported as it would have been. A transform that matches an error Polecat also translates, such as a duplicate key (2627) that would have been a DocumentAlreadyExistsException, replaces that translation for this store. Transforms belong to the store they are registered on, never to the whole process.
They do not run for reads. Polecat translates nothing there, so a failed query or raw SQL read reports the SqlException it was, and the lock failures of FetchForExclusiveWriting and AppendExclusive stay StreamLockedException. This is narrower than Marten, whose Advanced.ExceptionTransforms also covers raw SQL and LINQ queries.

JasperFx provides formal support for Polecat and other Critter Stack libraries. Please check our