Class NpgsqlTransaction
Represents a transaction to be made in a PostgreSQL database. This class cannot be inherited.
Inheritance
Namespace: Npgsql
Assembly: Npgsql.dll
Syntax
public sealed class NpgsqlTransaction : DbTransaction
Properties
| Improve this Doc View SourceConnection
Specifies the NpgsqlConnection object associated with the transaction.
Declaration
public NpgsqlConnection? Connection { get; }
Property Value
Type | Description |
---|---|
NpgsqlConnection | The NpgsqlConnection object associated with the transaction. |
DbConnection
Specifies the NpgsqlConnection object associated with the transaction.
Declaration
protected override DbConnection? DbConnection { get; }
Property Value
Type | Description |
---|---|
DbConnection? | The NpgsqlConnection object associated with the transaction. |
IsolationLevel
Specifies the isolation level for this transaction.
Declaration
public override IsolationLevel IsolationLevel { get; }
Property Value
Type | Description |
---|---|
IsolationLevel | The isolation level for this transaction. The default is |
SupportsSavepoints
Indicates whether this transaction supports database savepoints.
Declaration
public bool SupportsSavepoints { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
| Improve this Doc View SourceCommit()
Commits the database transaction.
Declaration
public override void Commit()
CommitAsync(CancellationToken)
Commits the database transaction.
Declaration
public override Task CommitAsync(CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
Task |
Dispose(bool)
Disposes the transaction, rolling it back if it is still pending.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
DisposeAsync()
Disposes the transaction, rolling it back if it is still pending.
Declaration
public override ValueTask DisposeAsync()
Returns
Type | Description |
---|---|
ValueTask |
Release(string)
Releases a transaction from a pending savepoint state.
Declaration
public void Release(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the savepoint. |
ReleaseAsync(string, CancellationToken)
Releases a transaction from a pending savepoint state.
Declaration
public Task ReleaseAsync(string name, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the savepoint. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
Task |
Rollback()
Rolls back a transaction from a pending state.
Declaration
public override void Rollback()
Rollback(string)
Rolls back a transaction from a pending savepoint state.
Declaration
public void Rollback(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the savepoint. |
RollbackAsync(CancellationToken)
Rolls back a transaction from a pending state.
Declaration
public override Task RollbackAsync(CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
Task |
RollbackAsync(string, CancellationToken)
Rolls back a transaction from a pending savepoint state.
Declaration
public Task RollbackAsync(string name, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the savepoint. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
Task |
Save(string)
Creates a transaction save point.
Declaration
public void Save(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the savepoint. |
Remarks
This method does not cause a database roundtrip to be made. The savepoint creation statement will instead be sent along with the next command.
SaveAsync(string, CancellationToken)
Creates a transaction save point.
Declaration
public Task SaveAsync(string name, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the savepoint. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
Task |
Remarks
This method does not cause a database roundtrip to be made, and will therefore always complete synchronously. The savepoint creation statement will instead be sent along with the next command.