Table of Contents

Method BeginTransaction

Namespace
YndigoBlue.Velocity.Engine
Assembly
YndigoBlue.Velocity.dll

BeginTransaction(IsolationLevel)

Begins a database transaction with a specific isolation level.

public void BeginTransaction(IsolationLevel isolationLevel)

Parameters

isolationLevel IsolationLevel

The IsolationLevel for the transaction.

Examples

using (var m = new Manager(conn))
{
    var schema = m.LoadSchema("app");
    var accountsTable = schema["accounts"];

    try
    {
        // Start transaction with serializable isolation
        m.BeginTransaction(System.Data.IsolationLevel.Serializable);

        // Perform multiple operations
        var update1 = new Update(accountsTable);
        update1.Set(accountsTable["balance"], accountsTable["balance"] - 100);
        update1.AddWhere(accountsTable["id"], Operator.Equals, 1);
        m.UpdateRecords(update1);

        var update2 = new Update(accountsTable);
        update2.Set(accountsTable["balance"], accountsTable["balance"] + 100);
        update2.AddWhere(accountsTable["id"], Operator.Equals, 2);
        m.UpdateRecords(update2);

        m.CommitTransaction();
    }
    catch
    {
        m.RollbackTransaction();
        throw;
    }
}

Remarks

All subsequent database operations through this Manager will be part of the transaction until CommitTransaction or RollbackTransaction is called.

Exceptions

DbException

Thrown when a database error occurs.

BeginTransaction()

Begins a database transaction with the default isolation level.

public void BeginTransaction()

Examples

using (var m = new Manager(conn))
{
    var schema = m.LoadSchema("app");
    var ordersTable = schema["orders"];

    m.BeginTransaction();

    try
    {
        // Multiple insert operations
        for (int i = 0; i < 10; i++)
        {
            var record = new Record(ordersTable);
            record.SetFieldInteger("product_id", i);
            record.SetFieldInteger("quantity", 1);
            m.AddRecordNoIdentity(record);
        }

        m.CommitTransaction();
    }
    catch
    {
        m.RollbackTransaction();
        throw;
    }
}

Remarks

Uses the database's default isolation level. All subsequent operations will be part of the transaction.

Exceptions

DbException

Thrown when a database error occurs.