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, ISerializableInherits 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:
kindTenantIsolationViolationKind: Which isolation check failed.typeNamestring: The CLR type name of the entity, or of theDbContextforTenantIsolationViolationKind.TenantDatabaseMismatch.messagestring: Why the operation was rejected.offendingTenantIdstring: The tenant the rejected entity or database belongs to, when known.expectedTenantIdstring: The current tenant, when known.
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
SaveWithoutTransactionBehavior enum
What SaveChanges does, with Database.AutoTransactionBehavior set to Never and no transaction, when the tenant check of some rows it writes is another of its statements: owned rows in a table of their own, checked by their owner's statement, and the rows of an entity mapped to more than one table table-per-type, entity splitting, checked in the table with TenantId.
TenantIsolationViolationKind enum
Which isolation check threw a TenantIsolationViolationExceptiontenantry-efcore-tenantisolationviolationexception.md.