Multi-Tenanted Documents
Polecat supports isolating document data by tenant using conjoined tenancy (shared tables with a tenant_id column) or separate database tenancy.
Conjoined Tenancy
When conjoined tenancy is enabled, all document tables include a tenant_id column and use a composite primary key of (tenant_id, id):
var store = DocumentStore.For(opts =>
{
opts.Connection("...");
opts.Events.TenancyStyle = TenancyStyle.Conjoined;
});Querying
All queries automatically filter by the session's tenant ID:
await using var session = store.LightweightSession(new SessionOptions
{
TenantId = "tenant-a"
});
// Only returns documents belonging to "tenant-a"
var orders = await session.Query<Order>().ToListAsync();Loading by ID
// Only loads if the document belongs to the session's tenant
var order = await session.LoadAsync<Order>(orderId);Separate Database Tenancy
Each tenant gets a completely separate SQL Server database:
var store = DocumentStore.For(opts =>
{
opts.MultiTenantedDatabases(databases =>
{
databases.AddTenant("tenant-a", "Server=localhost;Database=tenant_a;...");
databases.AddTenant("tenant-b", "Server=localhost;Database=tenant_b;...");
});
});Sessions are automatically routed to the correct database.
No default tenant — and no top level connection string
MultiTenantedDatabases() (and MultiTenantedMasterTable()) sets StoreOptions.DefaultTenantUsageEnabled to false. Do not register a placeholder *DEFAULT* tenant, and you do not need to set StoreOptions.ConnectionString — the tenancy supplies one. Opening a session or building a daemon without a tenant throws DefaultTenantUsageDisabledException rather than quietly using whichever database happened to be first.
The async daemon starts one daemon per tenant database with the default tenant disabled, and ApplyAllDatabaseChangesOnStartup() migrates every tenant database. See No default tenant is required.
ITenanted Interface
Documents implementing ITenanted have their TenantId property automatically synced:
public class Order : ITenanted
{
public Guid Id { get; set; }
public string TenantId { get; set; } = "";
public string Description { get; set; } = "";
}
// When stored, order.TenantId is automatically set to the session's tenantSee Multi-Tenancy Configuration for complete setup details.

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