UnitOfWork class
namespace: Serenity.Data assembly: Serenity.Net.Services
Unit of work implementation.
public class UnitOfWork : IAsyncDisposable, IDisposable, IUnitOfWork
Public Members
| name | description |
|---|---|
| UnitOfWork(…) | Initializes a new instance of the UnitOfWork class. (3 constructors) |
| Connection { get; } | Gets the connection. |
| HasStartedTransaction { get; } | Gets whether the unit of work's transaction was actually started. Unlike Initialized, which is also true when the start was attempted but failed, this is only set after BeginTransaction succeeds. Once true it stays true, including after commit, rollback and dispose. |
| Initialized { get; } | Returns true if the transaction is tried to be started at least once. This always returns true if deferStart is not true. |
| event OnCommit | Occurs when Commit completes without error. This signals operation success, not necessarily a database transaction commit: when no underlying transaction exists the event still fires. |
| event OnRollback | Occurs when the unit of work is disposed without a prior Commit. This is tied to the operation outcome, not to a database transaction: it also fires when no underlying transaction was ever started. |
| Commit() | Commits this transaction. |
| CommitAsync(…) | Commits this transaction asynchronously. |
| Dispose() | Rollbacks the transaction if any and calls onRollback event. |
| DisposeAsync() | Rollbacks the transaction if any and calls onRollback event asynchronously. |
See Also
- interface IUnitOfWork
- Source: UnitOfWork.cs