Method LeaseAsync(CancellationToken)
Lends the connection this redb connection works on for the caller's own commands, in the transaction
redb's commands run in: redb's explicit transaction (,
), else the ambient
(its one connection per database), else no transaction.
Build the commands with : it binds the transaction the
driver requires (SQLite always, SQL Server in an explicit transaction).
The lease enters the same command gates a redb command enters, so it is one command's hold: release it
with await using as soon as the commands are done. While it is held, redb on this connection or in
the same ambient transaction is refused at once. What the holder must never do is listed on
.
The lease is on this connection only, so on the connection of the redb service the caller resolved. A named
redb service has a connection of its own; an explicit transaction belongs to the DI scope that began it, and a
connection of another scope lends its own connection outside that transaction. Inside a
every scope of the same database lends the scope's
connection.
For a long-lived owner of the connection (EF Core, PostgreSQL COPY, SqlBulkCopy) use
instead: it holds no gate, so its work and redb's must run
strictly one after the other.
The default body throws : a connection outside the redb providers
has to lend its connection itself.
public Task<RedbConnectionLease> LeaseAsync(CancellationToken cancellationToken = default)