Class NpgsqlTransaction
Represents a transaction to be made in a PostgreSQL database. This class cannot be inherited.
Inherited Members
Namespace: Npgsql
Assembly: Npgsql.dll
Syntax
public sealed class NpgsqlTransaction : DbTransaction, IDbTransaction, IDisposable, IAsyncDisposable
Properties
Connection
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. |
Overrides
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 ReadCommitted. |
Overrides
Methods
Commit()
Commits the database transaction.
Declaration
public override void Commit()
Overrides
CommitAsync(CancellationToken)
Commits the database transaction.
Declaration
public override Task CommitAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is None. |
Returns
Type | Description |
---|---|
Task |
Overrides
Dispose(Boolean)
Disposes the transaction, rolling it back if it is still pending.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing |
Overrides
DisposeAsync()
Disposes the transaction, rolling it back if it is still pending.
Declaration
public override ValueTask DisposeAsync()
Returns
Type | Description |
---|---|
ValueTask |
Overrides
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 = default(CancellationToken))
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 None. |
Returns
Type | Description |
---|---|
Task |
Rollback()
Rolls back a transaction from a pending state.
Declaration
public override void Rollback()
Overrides
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(String, CancellationToken)
Rolls back a transaction from a pending savepoint state.
Declaration
public Task RollbackAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
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 None. |
Returns
Type | Description |
---|---|
Task |
RollbackAsync(CancellationToken)
Rolls back a transaction from a pending state.
Declaration
public override Task RollbackAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is None. |
Returns
Type | Description |
---|---|
Task |
Overrides
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 = default(CancellationToken))
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 None. |
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.