Table of Contents

Class UnitOfWork

Namespace
IceCoffee.Db4Net
Assembly
IceCoffee.Db4Net.dll

Represents a unit of work, managing a database connection and transaction.

public class UnitOfWork : IDisposable
Inheritance
UnitOfWork
Implements
Inherited Members

Constructors

UnitOfWork(DbConnection)

Initializes a new instance of the UnitOfWork class.

public UnitOfWork(DbConnection connection)

Parameters

connection DbConnection

The database connection.

UnitOfWork(DbConnection, IsolationLevel)

Initializes a new instance of the UnitOfWork class with the specified isolation level.

public UnitOfWork(DbConnection connection, IsolationLevel il)

Parameters

connection DbConnection

The database connection.

il IsolationLevel

The isolation level for the transaction.

Properties

DbConnection

Gets the database connection.

public IDbConnection DbConnection { get; }

Property Value

IDbConnection

DbTransaction

Gets the database transaction.

public IDbTransaction DbTransaction { get; }

Property Value

IDbTransaction

Methods

Commit()

Commits the current transaction. If the commit fails, the transaction is rolled back. After committing, the UnitOfWork instance is considered "done" and its transaction/connection will be disposed upon exiting the using block.

public void Commit()

CommitAsync()

Asynchronously commits the current transaction. If the commit fails, the transaction is rolled back. After committing, the UnitOfWork instance is considered "done" and its transaction/connection will be disposed upon exiting the using block.

public Task CommitAsync()

Returns

Task

Dispose()

Releases all resources used by the UnitOfWork.

public void Dispose()

Dispose(bool)

Releases the unmanaged resources used by the UnitOfWork and optionally releases the managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.