# Google Cloud Spanner v1 API - Class ManagedTransaction (5.13.0-beta07)

5.13.0-beta07 5.13.0-beta06 5.12.0 (latest) 5.11.0 5.10.0 5.9.0 5.8.0 5.7.0 5.6.0 5.5.0 5.4.0 5.3.0 5.2.0 5.1.0 5.0.0 4.6.0 4.5.0 4.4.0 4.3.0 4.2.0 4.1.0 4.0.0 3.15.1 3.14.0 3.13.0 3.12.0 3.11.0 3.10.0 3.9.0 3.8.0 3.7.0 3.6.0 3.5.0

    public sealed class ManagedTransaction : IAsyncDisposable

Reference documentation and code samples for the Google Cloud Spanner v1 API class ManagedTransaction.

A managed transaction that will acquire a Spanner transaction as needed and apply it to requests
executed with it.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> ManagedTransaction

## Implements

[IAsyncDisposable](https://learn.microsoft.com/dotnet/api/system.iasyncdisposable)

## Inherited Members

[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Cloud.Spanner.V1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1)

## Assembly

Google.Cloud.Spanner.V1.dll

## Remarks


Each method in this class modifies requests passed as arguments to RPC methods, to populate
the session and transaction properties.

## Properties

### ReadTimestamp

    public Timestamp ReadTimestamp { get; }

The read timestamp of the transaction. May be null.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Timestamp.html` |   |

**Remarks** Will be set iif a transaction has been started and [TransactionOptions](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.TransactionOptions) represents read-only options
with [ReturnReadTimestamp](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.TransactionOptions.Types.ReadOnly#Google_Cloud_Spanner_V1_TransactionOptions_Types_ReadOnly_ReturnReadTimestamp) set to true
or if this session was created using [FromTransaction(SpannerClient, Session, ByteString, TransactionOptions, Timestamp)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ManagedTransaction#Google_Cloud_Spanner_V1_ManagedTransaction_FromTransaction_Google_Cloud_Spanner_V1_SpannerClient_Google_Cloud_Spanner_V1_Session_Google_Protobuf_ByteString_Google_Cloud_Spanner_V1_TransactionOptions_Google_Protobuf_WellKnownTypes_Timestamp_)
and a non-null was provided for the [Timestamp](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Timestamp.html) parameter.

### SessionName

    public SessionName SessionName { get; }

The name of the session. This is never null.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionName` |   |

### TransactionId

    public ByteString TransactionId { get; }

The ID of the transaction. Will be null if a Spanner transaction hasn't been created yet.
Spanner transaction is usually created when the first command that requires a transaction is
executed via this [ManagedTransaction](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ManagedTransaction).

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html` |   |

## Methods

### CommitAsync(CommitRequest, CallSettings)

    public Task<CommitResponse> CommitAsync(CommitRequest request, CallSettings callSettings)

Executes a Commit RPC asynchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.CommitRequest` The commit request. Must not be null. The request will be modified with session and transaction details from this object. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to this RPC call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.CommitResponse` | A task representing the asynchronous operation. When the task completes, the result is the response from the RPC. |

### DisposeAsync()

    public ValueTask DisposeAsync()

Rollbacks the Spanner transaction if it was read/write, it hasn't been committed or rollbacked
and the managed transaction is not shared.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask` |   |

### ExecuteBatchDmlAsync(ExecuteBatchDmlRequest, CallSettings)

    public Task<ExecuteBatchDmlResponse> ExecuteBatchDmlAsync(ExecuteBatchDmlRequest request, CallSettings callSettings)

Executes an ExecuteBatchDml RPC asynchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteBatchDmlRequest` The query request. Must not be null. The request will be modified with session and transaction details from this object. If this object's [TransactionId](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ManagedTransaction#Google_Cloud_Spanner_V1_ManagedTransaction_TransactionId) is null, the request's transaction is not modified. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to this RPC call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteBatchDmlResponse` | A task representing the asynchronous operation. When the task completes, the result is the response from the RPC. |

### ExecuteSqlAsync(ExecuteSqlRequest, CallSettings)

    public Task<ResultSet> ExecuteSqlAsync(ExecuteSqlRequest request, CallSettings callSettings)

Executes an ExecuteSql RPC asynchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteSqlRequest` The query request. Must not be null. Will be modified to include session information. May be modified to include transaction and directed read options information. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to this RPC call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ResultSet` | A task representing the asynchronous operation. When the task completes, the result is the response from the RPC. |

### ExecuteSqlStreamReader(ExecuteSqlRequest, CallSettings)

    public ReliableStreamReader ExecuteSqlStreamReader(ExecuteSqlRequest request, CallSettings callSettings)

Creates a [ReliableStreamReader](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ReliableStreamReader) for the given request.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteSqlRequest` The query request. Must not be null. Will be modified to include session information. May be modified to include transaction and directed read options information. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to this RPC call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ReliableStreamReader` | A [ReliableStreamReader](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ReliableStreamReader) for the streaming SQL request. |

### FreshAfterAbort()

    public ManagedTransaction FreshAfterAbort()

Creates a new managed transaction from this one. This is useful for preserving lock ordering
in the event of the current transaction being aborted.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ManagedTransaction` |   |

### FromTransaction(SpannerClient, Session, ByteString, TransactionOptions, Timestamp)

    public static ManagedTransaction FromTransaction(SpannerClient client, Session session, ByteString transactionId, TransactionOptions transactionOptions, Timestamp readTimestamp)

Creates a [ManagedTransaction](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ManagedTransaction) associated to the pair `session`,
`transactionId`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `client` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SpannerClient` |
| `session` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.Session` |
| `transactionId` | `https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html` |
| `transactionOptions` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.TransactionOptions` |
| `readTimestamp` | `https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Timestamp.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ManagedTransaction` |   |

**Remarks** Note that no Spanner transaction will be started. The transaction identified by `transactionId`
should have been started or obtained earlier by the caller.

### PartitionQueryAsync(PartitionQueryRequest, CallSettings)

    public Task<PartitionResponse> PartitionQueryAsync(PartitionQueryRequest request, CallSettings callSettings)

Executes a PartitionQuery RPC asynchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PartitionQueryRequest` The partitioning request. Must not be null. The request will be modified with session details from this object. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to this RPC call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PartitionResponse` | A task representing the asynchronous operation. When the task completes, the result is the response from the RPC. |

### PartitionReadAsync(PartitionReadRequest, CallSettings)

    public Task<PartitionResponse> PartitionReadAsync(PartitionReadRequest request, CallSettings callSettings)

Executes a PartitionRead RPC asynchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PartitionReadRequest` The partitioning request. Must not be null. The request will be modified with session details from this object. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to this RPC call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PartitionResponse` | A task representing the asynchronous operation. When the task completes, the result is the response from the RPC. |

### ReadStreamReader(ReadRequest, CallSettings)

    public ReliableStreamReader ReadStreamReader(ReadRequest request, CallSettings callSettings)

Creates a [ReliableStreamReader](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ReliableStreamReader) for the given request.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ReadRequest` The read request. Must not be null. Will be modified to include session information. May be modified to include transaction and directed read options information. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to this RPC call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ReliableStreamReader` | A [ReliableStreamReader](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ReliableStreamReader) for the streaming SQL request. |

### RollbackAsync(RollbackRequest, CallSettings)

    public Task RollbackAsync(RollbackRequest request, CallSettings callSettings)

Executes a Rollback RPC asynchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.RollbackRequest` The rollback request. Must not be null. The request will be modified with session and transaction details from this object. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to this RPC call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A task representing the asynchronous operation. |