Member Junction
    Preparing search index...

    Function RunInEntityTransaction

    • Runs work inside a provider-arbitrated transaction scope, committing on success and rolling back on any thrown error.

      This is the preferred entry point — it makes the settle-once contract impossible to get wrong and keeps the try/catch boilerplate in one place.

      Type Parameters

      • T

      Parameters

      • provider: {
            SupportsEntityTransactions?: boolean;
            BeginEntityTransaction?(): Promise<EntityTransactionScope>;
        }

        The provider to obtain the scope from. When it does not support entity transactions the work still runs, just without transactional guarantees — callers needing atomicity must check SupportsEntityTransactions first and route the unit of work to the server instead.

      • work: () => Promise<T>

        The work to perform inside the scope.

      Returns Promise<T>

      Whatever work returns.

      const total = await RunInEntityTransaction(this.ProviderToUse, async () => {
      await header.Save();
      for (const line of lines) await line.Save();
      return lines.length;
      });

      Re-throws whatever work throws, after rolling the scope back.