Skip to content

Transactions

TIP

Transactions appear at several layers: SQLBuilder (disposable scope), BatchSQL (queue then execute), and UnitOfWork (repository mode).

WARNING

After kit.beginTransaction(), useClip, useRepo, and entity helpers participate in the same transaction. insertList batching does as well.

SQLBuilder

  • After beginTransaction, subsequent work shares one transaction until commit/rollback.
  • Prefer using so resources dispose correctly.

beginTransaction

c#
kit.beginTransaction();

commit

c#
kit.commit();

useTransaction

Advanced: attach an external IDbTransaction. Use only when you understand the scope.

c#
kit.useTransaction(transaction);

Example

c#
using (kit) { 
    kit.beginTransaction();
    foreach (var bill in bills) { 
        kit.clear()
            .setTable("table")
            .set("DATE", bill.SendStart)
            .where("OID", bill.DueInCoalOID)
            .doUpdate();
        cc++;
    }
    if (cc > 0) { 
        kit.commit();
    }
}

BatchSQL

See BatchSQL.

Unit of work

See Unit of work.