Per-tenant data isolation for EF Core, in a shared database, a database per tenant, or a mix of both.
MultiTenant Entity Framework Core keeps each tenant's data separate. Mark entities as multi-tenant and queries, inserts, and updates stay within the current tenant.
Use a shared database with automatic filtering, a database per tenant chosen from tenant info, or a hybrid of both. It also provides an EF Core tenant store.
dotnet add package Finbuckle.MultiTenant.EntityFrameworkCore
builder.Services.AddMultiTenant<AppTenantInfo, string>()
.WithHostStrategy()
.WithConfigurationStore();
builder.Services.AddMultiTenantDbContext<AppDbContext, string>(options =>
options.UseSqlServer(connectionString));Releases
| Version | Targets | Released | Release notes |
|---|---|---|---|
| v11.0.0New | .NET 11 | Nov 24, 2026 | Release notes |
| v10.2.0 | .NET 10 | Nov 12, 2026 | Release notes |
| v9.4.16 | .NET 8 and 9 | Nov 10, 2026 | Release notes |
| v8.1.21 | .NET 6, 7, and 8 | Nov 10, 2026 | Release notes |
A database per tenant
Give each tenant its own database, or move only your largest tenants to dedicated ones, by choosing the connection from the tenant's details.
- Pick the connection string or provider for each tenant.
- Mix shared and dedicated databases in one app.
- Pooled DbContext registration for high-throughput apps.
builder.Services.AddMultiTenantDbContext<AppDbContext, string>((sp, options) =>
{
var tenant = sp
.GetRequiredService<ITenantContext<AppTenantInfo, string>>()
.TenantInfo;
options.UseSqlServer(tenant?.ConnectionString);
});Writes that can't cross tenants
Saving changes checks every tracked entity against the context's tenant, so data can't be written to the wrong tenant by mistake.
- A tenant mismatch throws by default; ignore or overwrite if you prefer.
- New entities saved without a tenant ID get the current one.
- Query across tenants deliberately with IgnoreQueryFilters.
var invoice = new Invoice { Amount = 120m };
db.Invoices.Add(invoice);
// TenantId is set from the current tenant
await db.SaveChangesAsync();
// only the current tenant's invoices
var unpaid = await db.Invoices
.Where(i => i.Amount > 0)
.ToListAsync();Store tenants in EF Core
Keep your tenant list in a database you already run, managed through EF Core migrations like the rest of your schema.
- Works with any EF Core provider.
- Combine it with a distributed cache to keep lookups fast.
- Add, update, and remove tenants at runtime with TenantManager.
public class TenantStoreDbContext(DbContextOptions options)
: EFCoreStoreDbContext<AppTenantInfo, string>(options);
builder.Services.AddMultiTenant<AppTenantInfo, string>()
.WithHostStrategy()
.WithDistributedCacheStoreCache()
.WithEFCoreStore<TenantStoreDbContext, AppTenantInfo, string>();The rest of the MultiTenant family
MultiTenant Abstractions
Finbuckle.
The shared contracts: tenant info, strategy, store, and tenant context interfaces, with no implementation dependencies.
Learn moreMultiTenant
Finbuckle.
The foundation: tenant resolution, tenant stores, per-tenant options, and running work as a tenant in any .NET app.
Learn moreMultiTenant for ASP.NET Core
Finbuckle.
Middleware, request-based strategies, and per-tenant authentication for ASP.NET Core apps.
Learn moreMultiTenant Identity
Finbuckle.
Multi-tenant ASP.NET Core Identity: each tenant gets its own users, roles, and passkeys.
Learn more