Table of Contents

Class NpgsqlTransaction

Namespace
Npgsql
Assembly
Npgsql.dll

Represents a transaction to be made in a PostgreSQL database. This class cannot be inherited.

public sealed class NpgsqlTransaction : DbTransaction, IDbTransaction, IDisposable, IAsyncDisposable
Inheritance
NpgsqlTransaction
Implements
Inherited Members

Properties

Connection

Specifies the NpgsqlConnection object associated with the transaction.

public NpgsqlConnection? Connection { get; }

Property Value

NpgsqlConnection

The NpgsqlConnection object associated with the transaction.

DbConnection

Specifies the NpgsqlConnection object associated with the transaction.

protected override DbConnection? DbConnection { get; }

Property Value

DbConnection

The NpgsqlConnection object associated with the transaction.

IsolationLevel

Specifies the isolation level for this transaction.

public override IsolationLevel IsolationLevel { get; }

Property Value

IsolationLevel

The isolation level for this transaction. The default is ReadCommitted.

SupportsSavepoints

Indicates whether this transaction supports database savepoints.

public override bool SupportsSavepoints { get; }

Property Value

bool

Methods

Commit()

Commits the database transaction.

public override void Commit()

CommitAsync(CancellationToken)

Commits the database transaction.

public override Task CommitAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

An optional token to cancel the asynchronous operation. The default value is None.

Returns

Task

Dispose(bool)

Disposes the transaction, rolling it back if it is still pending.

protected override void Dispose(bool disposing)

Parameters

disposing bool

DisposeAsync()

Disposes the transaction, rolling it back if it is still pending.

public override ValueTask DisposeAsync()

Returns

ValueTask

Release(string)

Releases a transaction from a pending savepoint state.

public override void Release(string name)

Parameters

name string

The name of the savepoint.

ReleaseAsync(string, CancellationToken)

Releases a transaction from a pending savepoint state.

public override Task ReleaseAsync(string name, CancellationToken cancellationToken = default)

Parameters

name string

The name of the savepoint.

cancellationToken CancellationToken

An optional token to cancel the asynchronous operation. The default value is None.

Returns

Task

Rollback()

Rolls back a transaction from a pending state.

public override void Rollback()

Rollback(string)

Rolls back a transaction from a pending savepoint state.

public override void Rollback(string name)

Parameters

name string

The name of the savepoint.

RollbackAsync(string, CancellationToken)

Rolls back a transaction from a pending savepoint state.

public override Task RollbackAsync(string name, CancellationToken cancellationToken = default)

Parameters

name string

The name of the savepoint.

cancellationToken CancellationToken

An optional token to cancel the asynchronous operation. The default value is None.

Returns

Task

RollbackAsync(CancellationToken)

Rolls back a transaction from a pending state.

public override Task RollbackAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

An optional token to cancel the asynchronous operation. The default value is None.

Returns

Task

Save(string)

Creates a transaction save point.

public override void Save(string name)

Parameters

name string

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.

public override Task SaveAsync(string name, CancellationToken cancellationToken = default)

Parameters

name string

The name of the savepoint.

cancellationToken CancellationToken

An optional token to cancel the asynchronous operation. The default value is None.

Returns

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.