Practice ยท 3 of 3
Debug: The Half-Written Transfer
CHALLENGE
Difficulty: intermediate+25 XP
Transfer inserts a debit row and a credit row. A downstream constraint failure (set CjDb.FailOnInsertNumber = 2 in the test) means the SECOND insert can fail โ and the buggy version leaves the debit visible: a half-written ledger. Fix: wrap BOTH inserts in a transaction (BeginTransaction ... CommitTransaction) so the write is all-or-nothing: on failure, NOTHING is committed; on success, both rows land.
``csharp
static void Transfer(CjDb db, string from, string to);
// CjDb: BeginTransaction(), CommitTransaction(), PendingTransactions property
``
Press Submit to check your solution.
Back to lesson: Practice: Data Practice: Parameters, Mapping, Transactions