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()

public void BeginTransaction()