SaveWithoutTransactionBehavior enum
Namespace: Tenantry.EfCore · Package: Tenantry.EfCore · API reference
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. Without a transaction, a statement EF Core sends beside a check that fails would stay written. Set with EfCoreIsolationOptions.OnSaveWithoutTransaction.
public enum SaveWithoutTransactionBehaviorValues
| Value | Description |
|---|---|
UseTransaction = 0 | Run that save in a transaction EF Core begins and commits itself, as it does by default (AutoTransactionBehavior.WhenNeeded), and set Never back when the save ends. Other saves stay without one. The default. |
Reject = 1 | Throw TenantIsolationViolationException, of kind TenantIsolationViolationKind.SaveWithoutTransaction, before anything is sent. For a database or connection pooler that cannot run transactions. |
MissingTenantBehavior enum
What SaveChanges does when it writes tenant-owned entities and no tenant is current.
TenantIsolationViolationException class
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.