Class UnitOfWork
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
connectionDbConnectionThe 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
connectionDbConnectionThe database connection.
ilIsolationLevelThe isolation level for the transaction.
Properties
DbConnection
Gets the database connection.
public IDbConnection DbConnection { get; }
Property Value
DbTransaction
Gets the database transaction.
public IDbTransaction DbTransaction { get; }
Property Value
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
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
disposingbooltrue to release both managed and unmanaged resources; false to release only unmanaged resources.