Docs
Tenantry CoreAPI reference

TenantIsolationViolationException class

Namespace: Tenantry.EfCore · Package: Tenantry.EfCore · API reference

Thrown when EF Core would read or write across tenants: before SaveChanges writes another tenant's entity, before an ExecuteUpdate that could move rows between tenants, before a pooled database-per-tenant context uses another tenant's database, on the first use of a model that does not isolate a tenant-owned entity type, before a save that must succeed or fail as a whole runs without a transaction it may not begin, or instead of committing a transaction that holds a save whose tenant check failed and could not be undone. Nothing has been written when it is thrown, or, for a commit, kept: the transaction is rolled back. TenantIsolationViolationException.Kind says which.

public sealed class TenantIsolationViolationException : InvalidOperationException, ISerializable

Inherits Exception → SystemException → InvalidOperationException.

Implements ISerializable.

Constructors

TenantIsolationViolationException(TenantIsolationViolationKind, string, string, string?, string?)

Initialises a new instance.

public TenantIsolationViolationException(TenantIsolationViolationKind kind, string typeName, string message, string? offendingTenantId = null, string? expectedTenantId = null)

Parameters:

Properties

ExpectedTenantId

The current tenant, or null when none is current or the check does not use it.

public string? ExpectedTenantId { get; }

Value: string

Kind

Which isolation check failed.

public TenantIsolationViolationKind Kind { get; }

Value: TenantIsolationViolationKind

OffendingTenantId

The tenant the rejected entity or database belongs to, or null when the check does not know one (a bulk update, a model check).

public string? OffendingTenantId { get; }

Value: string

TypeName

The CLR type name of the entity that caused the violation, or of the DbContext for TenantIsolationViolationKind.TenantDatabaseMismatch.

public string TypeName { get; }

Value: string

On this page