Using Transactions

To perform transactional DB operations:

For example:

[C#]

using(MyDatabase db = new MyDatabase())
{
    // Begin the transaction
    db.BeginTransaction();
    try
    {
        // Your DB code.
        UserRow user = db.UserTable.GetByPrimaryKey("John", "Smith");
        user.City = "Dallas";
        db.UserTable.Update(user);

        user = db.UserTable.GetByPrimaryKey("Amy", "Smith");
        user.City = "Dallas";
        db.UserTable.Update(user);

        // Commit the transaction
        db.CommitTransaction();

        // Both records are updated
    }
    catch (Exception)
    {
        // Rollback the transaction
        db.RollbackTransaction();

        // Neither record was updated
    }
}

or

MyDatabase db = new MyDatabase();
try
{
    // Begin the transaction
    db.BeginTransaction();
    try
    {
        // Your DB code.
        UserRow user = db.UserTable.GetByPrimaryKey("John", "Smith");
        user.City = "Dallas";
        db.UserTable.Update(user);

        user = db.UserTable.GetByPrimaryKey("Amy", "Smith");
        user.City = "Dallas";
        db.UserTable.Update(user);

        // Commit the transaction
        db.CommitTransaction();

        // Both records are updated
    }
    catch (Exception)
    {
        // Rollback the transaction
        db.RollbackTransaction();

        // Neither record was updated
    }
}
finally
{
    db.Close();
}

[VB.NET]

Dim db As New MyDatabase()
Try
    ' Begin the transaction
    db.BeginTransaction()
    Try
        ' Your DB code.
        Dim user As UserRow
        user = db.UserTable.GetByPrimaryKey("John", "Smith")
        user.City = "Dallas"
        db.UserTable.Update(user)

        user = db.UserTable.GetByPrimaryKey("Amy", "Smith")
        user.City = "Dallas"
        db.UserTable.Update(user)

        ' Commit the transaction
        db.CommitTransaction()

        ' Both records are updated
    Catch e As Exception
        ' Rollback the transaction
        db.RollbackTransaction()

        ' Neither record was updated
    End Try
Finally
    db.Close()
End Try