5.2.0 (latest) 5.1.0 5.0.0 4.17.0 4.16.0 4.15.0 4.14.0 4.13.0 4.12.0 4.11.0 4.10.0 4.9.0 4.8.0 4.7.0 4.6.0 4.5.0 4.4.0 4.3.0 4.2.0 4.1.0 4.0.0 3.5.0 3.4.0 3.3.0 3.2.0

    public abstract class DatastoreTransaction : IDisposable, IAsyncDisposable

Reference documentation and code samples for the Google Cloud Datastore v1 API class DatastoreTransaction.


Convenience wrapper around a Datastore transaction. All mutation operations ([Insert(IEnumerable\<Entity\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Insert_System_Collections_Generic_IEnumerable_Google_Cloud_Datastore_V1_Entity__),
[Delete(IEnumerable\<Key\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Delete_System_Collections_Generic_IEnumerable_Google_Cloud_Datastore_V1_Key__), [Update(IEnumerable\<Entity\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Update_System_Collections_Generic_IEnumerable_Google_Cloud_Datastore_V1_Entity__) and [Upsert(IEnumerable\<Entity\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Upsert_System_Collections_Generic_IEnumerable_Google_Cloud_Datastore_V1_Entity__))
merely add to a list of mutations which are performed in a single [Commit(CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Commit_Google_Api_Gax_Grpc_CallSettings_) or [CommitAsync(CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_CommitAsync_Google_Api_Gax_Grpc_CallSettings_)
operation. This means the mutation methods are all synchronous and do not take call settings, as they don't perform any
API operations.

Datastore limits the number of entities that can be modified in a Commit operation, and therefore one transaction. When modifying a large
number of entities, partition the changes into multiple transactions. See
[Datastore limits](https://cloud.google.com/datastore/docs/concepts/limits) for more details on Datastore limits.


Even though transactions aren't inherently related to a specific partition ID, the expected usage is that queries run inside
a transaction are likely to be in a single partition, specified in a [DatastoreDb](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreDb) used to create the transaction.


Disposing of a transaction calls [Rollback(CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Rollback_Google_Api_Gax_Grpc_CallSettings_) if the transaction has not already been committed
or rolled back.


This is an abstract class, implemented by [DatastoreTransactionImpl](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransactionImpl) for production use. Users creating their own
[DatastoreDb](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreDb) subclasses may choose to create fake implementations for testing purposes. There are no abstract
methods in this class; instead, all methods either delegate to another or throw [NotImplementedException](https://learn.microsoft.com/dotnet/api/system.notimplementedexception).

## Inheritance

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

## Implements

[IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable), [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.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Derived Types

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

## Namespace

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

## Assembly

Google.Cloud.Datastore.V1.dll

## Properties

### TransactionId

    public virtual ByteString TransactionId { get; }

The ID of the transaction, used implicitly in operations performed with this object.

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

## Methods

### Commit(CallSettings)

    public virtual CommitResponse Commit(CallSettings callSettings = null)

Commits all mutations in this transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.CommitResponse` | The response from the commit operation. This can be used to determine server-allocated keys. |

**Remarks** Any entities with incomplete keys that are assigned keys by this operation will be updated in memory
with the server-allocated keys.

Datastore limits the number of entities that can be modified in a Commit operation, and therefore one transaction. When modifying a large
number of entities, partition the changes into multiple transactions. See
[Datastore limits](https://cloud.google.com/datastore/docs/concepts/limits) for more details on Datastore limits.
**Example**

    DatastoreDb db = DatastoreDb.Create(projectId, namespaceId);
    KeyFactory keyFactory = db.CreateKeyFactory("message");
    using (DatastoreTransaction transaction = db.BeginTransaction())
    {
        Entity entity = new Entity
        {
            Key = keyFactory.CreateIncompleteKey(),
            ["message"] = "Hello"
        };
        // This adds the entity to a collection in memory: nothing
        // is sent to the server.
        transaction.Insert(entity);
        // Without the Commit call, the transaction will automatically
        // be rolled back. The Commit call performs all the mutations
        // within the transaction.
        transaction.Commit();
    }

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.invalidoperationexception` | The transaction has already been committed or rolled back. |

### CommitAsync(CallSettings)

    public virtual Task<CommitResponse> CommitAsync(CallSettings callSettings = null)

Commits all mutations in this transaction asynchronously.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.CommitResponse` | The response from the commit operation. This can be used to determine server-allocated keys. |

**Remarks** Any entities with incomplete keys that are assigned keys by this operation will be updated in memory
with the server-allocated keys.

Datastore limits the number of entities that can be modified in a Commit operation, and therefore one transaction. When modifying a large
number of entities, partition the changes into multiple transactions. See
[Datastore limits](https://cloud.google.com/datastore/docs/concepts/limits) for more details on Datastore limits.
**Example**

See [Commit](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Commit_Google_Api_Gax_Grpc_CallSettings_) for a synchronous example.

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.invalidoperationexception` | The transaction has already been committed or rolled back. |

### Create(DatastoreClient, string, string, ByteString)

    public static DatastoreTransaction Create(DatastoreClient client, string projectId, string namespaceId, ByteString transactionId)

Constructs an instance of [DatastoreClientImpl](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreClientImpl) with the given arguments.
Clients using the [DatastoreDb](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreDb) abstraction layer would normally call
[BeginTransaction(CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreDb#Google_Cloud_Datastore_V1_DatastoreDb_BeginTransaction_Google_Api_Gax_Grpc_CallSettings_) or [BeginTransactionAsync(CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreDb#Google_Cloud_Datastore_V1_DatastoreDb_BeginTransactionAsync_Google_Api_Gax_Grpc_CallSettings_)
instead of calling this method directly.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `client` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreClient` The client to use for Datastore operations. Must not be null. |
| `projectId` | `https://learn.microsoft.com/dotnet/api/system.string` The ID of the project of the Datastore operations. Must not be null. |
| `namespaceId` | `https://learn.microsoft.com/dotnet/api/system.string` The ID of the namespace which is combined with `projectId` to form a partition ID to use in query operations. May be null. |
| `transactionId` | `https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html` The transaction obtained by an earlier [BeginTransaction(string, CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreClient#Google_Cloud_Datastore_V1_DatastoreClient_BeginTransaction_System_String_Google_Api_Gax_Grpc_CallSettings_) or the asynchronous equivalent. Must not be null |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction` | A [DatastoreTransaction](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction) representation of the specified transaction. |

### Create(DatastoreClient, string, string, string, ByteString)

    public static DatastoreTransaction Create(DatastoreClient client, string projectId, string namespaceId, string databaseId, ByteString transactionId)

Constructs an instance of [DatastoreClientImpl](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreClientImpl) with the given arguments.
Clients using the [DatastoreDb](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreDb) abstraction layer would normally call
[BeginTransaction(CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreDb#Google_Cloud_Datastore_V1_DatastoreDb_BeginTransaction_Google_Api_Gax_Grpc_CallSettings_) or [BeginTransactionAsync(CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreDb#Google_Cloud_Datastore_V1_DatastoreDb_BeginTransactionAsync_Google_Api_Gax_Grpc_CallSettings_)
instead of calling this method directly.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `client` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreClient` The client to use for Datastore operations. Must not be null. |
| `projectId` | `https://learn.microsoft.com/dotnet/api/system.string` The ID of the project of the Datastore operations. Must not be null. |
| `namespaceId` | `https://learn.microsoft.com/dotnet/api/system.string` The ID of the namespace which is combined with `projectId` and `databaseId` to form a partition ID to use in query operations. May be null. |
| `databaseId` | `https://learn.microsoft.com/dotnet/api/system.string` The ID of the database which is combined with `projectId` and `namespaceId` to form a partition ID to use in query operations. May be null. |
| `transactionId` | `https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html` The transaction obtained by an earlier [BeginTransaction(string, CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreClient#Google_Cloud_Datastore_V1_DatastoreClient_BeginTransaction_System_String_Google_Api_Gax_Grpc_CallSettings_) or the asynchronous equivalent. Must not be null |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction` | A [DatastoreTransaction](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction) representation of the specified transaction. |

### Delete(params Entity\[\])

    public virtual void Delete(params Entity[] entities)

Adds delete operations for all the specified keys to this transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `entities` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` The entities to delete. Must not be null. |

**Remarks** This method delegates to [Delete(IEnumerable\<Entity\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Delete_System_Collections_Generic_IEnumerable_Google_Cloud_Datastore_V1_Entity__).
**Example**

    DatastoreDb db = DatastoreDb.Create(projectId, namespaceId);
    KeyFactory keyFactory = db.CreateKeyFactory("message");
    Entity message = new Entity
    {
        Key = keyFactory.CreateIncompleteKey(),
        ["text"] = "Hello",
    };
    db.Insert(message);

    Entity fetchedBeforeDeletion = db.Lookup(message.Key);

    using (DatastoreTransaction transaction = db.BeginTransaction())
    {
        // This adds the entity key to a collection of mutations in memory: nothing
        // is sent to the server. Only the key from the entity is used to determine what to delete.
        // If you already have the key but not the entity, use Delete(Key[]) or
        // a similar overload.
        transaction.Delete(message);
        // Without the Commit call, the transaction will automatically
        // be rolled back. The Commit call performs all the mutations
        // within the transaction.
        transaction.Commit();
    }

    Entity fetchedAfterDeletion = db.Lookup(message.Key);

    Console.WriteLine($"Entity exists before deletion? {fetchedBeforeDeletion != null}");
    Console.WriteLine($"Entity exists after deletion? {fetchedAfterDeletion != null}");

### Delete(params Key\[\])

    public virtual void Delete(params Key[] keys)

Adds deletion operations for all the specified keys to this transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `keys` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Key` The keys to delete. Must not be null. |

**Remarks** This method delegates to [Delete(IEnumerable\<Key\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Delete_System_Collections_Generic_IEnumerable_Google_Cloud_Datastore_V1_Key__).
**Example**

    DatastoreDb db = DatastoreDb.Create(projectId, namespaceId);
    KeyFactory keyFactory = db.CreateKeyFactory("message");
    Entity message = new Entity
    {
        Key = keyFactory.CreateIncompleteKey(),
        ["text"] = "Hello",
    };
    Key key = db.Insert(message);

    Entity fetchedBeforeDeletion = db.Lookup(key);

    using (DatastoreTransaction transaction = db.BeginTransaction())
    {
        // This adds the key to a collection of mutations in memory: nothing
        // is sent to the server. Only the key is required to determine what to delete.
        // If you have an entity with the right key, you can use Delete(Entity[])
        // or a similar overload for convenience.
        transaction.Delete(key);
        // Without the Commit call, the transaction will automatically
        // be rolled back. The Commit call performs all the mutations
        // within the transaction.
        transaction.Commit();
    }

    Entity fetchedAfterDeletion = db.Lookup(key);

    Console.WriteLine($"Entity exists before deletion? {fetchedBeforeDeletion != null}");
    Console.WriteLine($"Entity exists after deletion? {fetchedAfterDeletion != null}");

### Delete(IEnumerable\<Entity\>)

    public virtual void Delete(IEnumerable<Entity> entities)

Adds delete operations for all the specified keys to this transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `entities` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` The entities to delete. Must not be null. |

**Example**

See [Delete](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Delete_Google_Cloud_Datastore_V1_Entity___) for an example using an alternative overload.

### Delete(IEnumerable\<Key\>)

    public virtual void Delete(IEnumerable<Key> keys)

Adds deletion operations for all the specified keys to this transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `keys` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Key` The keys to delete. Must not be null. |

**Example**

See [Delete](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Delete_Google_Cloud_Datastore_V1_Entity___) for an example using an alternative overload.

### Dispose()

    public virtual void Dispose()

If the transaction has already been committed, this operation is a no-op.
Otherwise, it rolls back the transaction.

### DisposeAsync()

    public virtual ValueTask DisposeAsync()

If the transaction has already been committed, this operation is a no-op.
Otherwise, it rolls back the transaction.

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

### Insert(params Entity\[\])

    public virtual void Insert(params Entity[] entities)

Adds insert operations for all the specified keys to this transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `entities` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` The entities to insert. Must not be null. |

**Remarks** This method delegates to [Insert(IEnumerable\<Entity\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Insert_System_Collections_Generic_IEnumerable_Google_Cloud_Datastore_V1_Entity__).
**Example**

    DatastoreDb db = DatastoreDb.Create(projectId, namespaceId);
    KeyFactory keyFactory = db.CreateKeyFactory("message");
    using (DatastoreTransaction transaction = db.BeginTransaction())
    {
        Entity entity = new Entity
        {
            Key = keyFactory.CreateIncompleteKey(),
            ["message"] = "Hello"
        };
        // This adds the entity to a collection in memory: nothing
        // is sent to the server.
        transaction.Insert(entity);
        // Without the Commit call, the transaction will automatically
        // be rolled back. The Commit call performs all the mutations
        // within the transaction.
        transaction.Commit();
    }

### Insert(IEnumerable\<Entity\>)

    public virtual void Insert(IEnumerable<Entity> entities)

Adds insert operations for all the specified keys to this transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `entities` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` The entities to insert. Must not be null. |

**Example**

See [Insert](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Insert_Google_Cloud_Datastore_V1_Entity___) for an example using an alternative overload.

### Lookup(Key, CallSettings)

    public virtual Entity Lookup(Key key, CallSettings callSettings = null)

Looks up a single entity by key.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Key` The key to look up. Must not be null, and must be complete. |
| `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.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` | The entity with the specified key, or `null` if no such entity exists. |

**Remarks** This method simply delegates to [Lookup(IEnumerable\<Key\>, CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Lookup_System_Collections_Generic_IEnumerable_Google_Cloud_Datastore_V1_Key__Google_Api_Gax_Grpc_CallSettings_).
**Example**

See [Lookup](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Lookup_Google_Cloud_Datastore_V1_Key___) for an example using an alternative overload.

### Lookup(params Key\[\])

    public virtual IReadOnlyList<Entity> Lookup(params Key[] keys)

Looks up a collection of entities by key.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `keys` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Key` The keys to look up. Must not be null, and every element must be non-null and refer to a complete key. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` | A collection of entities with the same size as `keys`, containing corresponding entity references, or `null` where the key was not found. |

**Remarks**
This call may perform multiple RPC operations in order to look up all keys.


This overload does not support the [CallSettings](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html) to be specified due to restrictions with
methods containing a parameter array and optional parameters.
It simply delegates to [Lookup(IEnumerable\<Key\>, CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Lookup_System_Collections_Generic_IEnumerable_Google_Cloud_Datastore_V1_Key__Google_Api_Gax_Grpc_CallSettings_), passing in a `null`
value for the call settings.

Datastore limits the number of entities that can be looked up in a single operation. When looking up a large
number of entities, partition the look-ups into batches. See
[Datastore limits](https://cloud.google.com/datastore/docs/concepts/limits) for more details on Datastore limits.
**Example**

    DatastoreDb db = DatastoreDb.Create(projectId, namespaceId);
    KeyFactory keyFactory = db.CreateKeyFactory("message");
    Entity message = new Entity { Key = keyFactory.CreateIncompleteKey(), ["text"] = "Original" };
    db.Insert(message);

    using (DatastoreTransaction transaction = db.BeginTransaction())
    {
        // Look the message up at the start of the transaction
        Entity fetched1 = transaction.Lookup(message.Key);
        Console.WriteLine((string) fetched1["text"]); // "Original"

        // Update the message outside the transaction
        message["text"] = "Updated";
        db.Update(message);

        // Look up the message up again. We are guaranteed not to see the
        // update because it occurred after the start of the transaction.
        Entity fetched2 = transaction.Lookup(message.Key);
        Console.WriteLine((string) fetched2["text"]); // Still "Original"
    }

### Lookup(IEnumerable\<Key\>, CallSettings)

    public virtual IReadOnlyList<Entity> Lookup(IEnumerable<Key> keys, CallSettings callSettings = null)

Looks up a collection of entities by key.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `keys` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Key` The keys to look up. Must not be null, and every element must be non-null and refer to a complete key. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` | A collection of entities with the same size as `keys`, containing corresponding entity references, or `null` where the key was not found. |

**Remarks** This call may perform multiple RPC operations in order to look up all keys.
**Example**

See [Lookup](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Lookup_Google_Cloud_Datastore_V1_Key___) for an example using an alternative overload.

### LookupAsync(Key, CallSettings)

    public virtual Task<Entity> LookupAsync(Key key, CallSettings callSettings = null)

Looks up a single entity by key asynchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Key` The key to look up. Must not be null, and must be complete. |
| `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.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` | The entity with the specified key, or `null` if no such entity exists. |

**Remarks** This method simply delegates to [LookupAsync(IEnumerable\<Key\>, CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_LookupAsync_System_Collections_Generic_IEnumerable_Google_Cloud_Datastore_V1_Key__Google_Api_Gax_Grpc_CallSettings_).
**Example**

See [Lookup](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Lookup_Google_Cloud_Datastore_V1_Key___) for a synchronous example.

### LookupAsync(params Key\[\])

    public virtual Task<IReadOnlyList<Entity>> LookupAsync(params Key[] keys)

Looks up a collection of entities by key asynchronously.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `keys` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Key` The keys to look up. Must not be null, and every element must be non-null and refer to a complete key. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` | A collection of entities with the same size as `keys`, containing corresponding entity references, or `null` where the key was not found. |

**Remarks**
This call may perform multiple RPC operations in order to look up all keys.


This overload does not support the [CallSettings](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html) to be specified due to restrictions with
methods containing a parameter array and optional parameters.
It simply delegates to [LookupAsync(IEnumerable\<Key\>, CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_LookupAsync_System_Collections_Generic_IEnumerable_Google_Cloud_Datastore_V1_Key__Google_Api_Gax_Grpc_CallSettings_), passing in a `null`
value for the call settings.

Datastore limits the number of entities that can be looked up in a single operation. When looking up a large
number of entities, partition the look-ups into batches. See
[Datastore limits](https://cloud.google.com/datastore/docs/concepts/limits) for more details on Datastore limits.
**Example**

See [Lookup](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Lookup_Google_Cloud_Datastore_V1_Key___) for a synchronous example.

### LookupAsync(IEnumerable\<Key\>, CallSettings)

    public virtual Task<IReadOnlyList<Entity>> LookupAsync(IEnumerable<Key> keys, CallSettings callSettings = null)

Looks up a collection of entities by key asynchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `keys` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Key` The keys to look up. Must not be null, and every element must be non-null and refer to a complete key. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` | A collection of entities with the same size as `keys`, containing corresponding entity references, or `null` where the key was not found. |

**Remarks** This call may perform multiple RPC operations in order to look up all keys.
**Example**

See [Lookup](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Lookup_Google_Cloud_Datastore_V1_Key___) for a synchronous example.

### Rollback(CallSettings)

    public virtual RollbackResponse Rollback(CallSettings callSettings = null)

Rolls back this transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

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

**Remarks** This method is rarely useful explicitly; the [Dispose()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Dispose) method rolls back the transaction if it
is still active, so a `using` statement is normally preferable to this.
**Example**

See \[RollbackAsync\] for an asynchronous example.

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.invalidoperationexception` | The transaction has already been committed or rolled back. |

### RollbackAsync(CallSettings)

    public virtual Task<RollbackResponse> RollbackAsync(CallSettings callSettings = null)

Rolls back this transaction asynchronously.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.RollbackResponse` |   |

**Remarks** This method is rarely useful explicitly; the [Dispose()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Dispose) method rolls back the transaction if it
is still active, so a `using` statement is normally preferable to this.
**Example**

    DatastoreDb db = DatastoreDb.Create(projectId, namespaceId);
    KeyFactory keyFactory = db.CreateKeyFactory("message");

    // Dispose automatically rolls back an uncommitted transaction synchronously.
    // To roll back asynchronously,
    bool committed = false;
    DatastoreTransaction transaction = await db.BeginTransactionAsync();
    try
    {
        Entity message = new Entity
        {
            Key = keyFactory.CreateIncompleteKey(),
            ["text"] = "Hello",
        };
        // This adds the entity to a collection in memory: nothing
        // is sent to the server.
        db.Insert(message);

        // Attempt to commit the transaction asynchronously.
        await transaction.CommitAsync();
        committed = true;
    }
    finally
    {
        if (!committed)
        {
            // Roll back asynchronously if anything failed.
            await transaction.RollbackAsync();
        }
    }

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.invalidoperationexception` | The transaction has already been committed or rolled back. |

### RunAggregationQuery(AggregationQuery, CallSettings)

    public virtual AggregationQueryResults RunAggregationQuery(AggregationQuery query, CallSettings callSettings = null)

Runs the given [AggregationQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQuery) in this transaction.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQuery` The [AggregationQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQuery) to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQueryResults` | The result of aggregation query. |

### RunAggregationQuery(DatastoreQuery, CallSettings)

    public virtual AggregationQueryResults RunAggregationQuery(DatastoreQuery query, CallSettings callSettings = null)

Runs the given [DatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQuery) in this transaction.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQuery` The [AggregationQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQuery) to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQueryResults` | The result of aggregation query. |

### RunAggregationQuery(GqlQuery, CallSettings)

    public virtual AggregationQueryResults RunAggregationQuery(GqlQuery query, CallSettings callSettings = null)

Runs the given [GqlQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.GqlQuery) in this transaction.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.GqlQuery` The [GqlQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.GqlQuery) to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQueryResults` | The result of aggregation query. |

### RunAggregationQueryAsync(AggregationQuery, CallSettings)

    public virtual Task<AggregationQueryResults> RunAggregationQueryAsync(AggregationQuery query, CallSettings callSettings = null)

Runs the given [AggregationQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQuery) in this transaction.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQuery` The [AggregationQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQuery) to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQueryResults` | A task representing the asynchronous operation. The result of the task is the result of the aggregation query. |

### RunAggregationQueryAsync(DatastoreQuery, CallSettings)

    public virtual Task<AggregationQueryResults> RunAggregationQueryAsync(DatastoreQuery query, CallSettings callSettings = null)

Runs the given [DatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQuery) in this transaction.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQuery` The [AggregationQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQuery) to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQueryResults` | A task representing the asynchronous operation. The result of the task is the result of the aggregation query. |

### RunAggregationQueryAsync(GqlQuery, CallSettings)

    public virtual Task<AggregationQueryResults> RunAggregationQueryAsync(GqlQuery query, CallSettings callSettings = null)

Runs the given [GqlQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.GqlQuery) in this transaction.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.GqlQuery` The [GqlQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.GqlQuery) to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AggregationQueryResults` | A task representing the asynchronous operation. The result of the task is the result of the aggregation query. |

### RunQuery(DatastoreQuery, CallSettings)

    public virtual DatastoreQueryResults RunQuery(DatastoreQuery query, CallSettings callSettings = null)

Runs the given query eagerly in this transaction, retrieving all results in memory and indicating whether more
results may be available beyond the query's limit. Use this method when your query has a limited
number of results, for example to build a web application which fetches results in pages.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQuery` The query to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQueryResults` | The complete query results. |

**Remarks**
Using a transaction ensures that a commit operation will fail if any of the entities returned
by this query have been modified while the transaction is active. Note that modifications performed
as part of this operation are not reflected in the query results.

The default implementation of this method delegates to [RunQueryLazily(Query, CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_RunQueryLazily_Google_Cloud_Datastore_V1_Query_Google_Api_Gax_Grpc_CallSettings_)
and calls [GetAllResults()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery#Google_Cloud_Datastore_V1_LazyDatastoreQuery_GetAllResults) on the return value.

### RunQuery(GqlQuery, CallSettings)

    public virtual DatastoreQueryResults RunQuery(GqlQuery query, CallSettings callSettings = null)

Runs the given query eagerly in this transaction, retrieving all results in memory and indicating whether more
results may be available beyond the query's limit. Use this method when your query has a limited
number of results, for example to build a web application which fetches results in pages.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.GqlQuery` The query to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQueryResults` | The complete query results. |

**Remarks**
Using a transaction ensures that a commit operation will fail if any of the entities returned
by this query have been modified while the transaction is active. Note that modifications performed
as part of this operation are not reflected in the query results.

The default implementation of this method delegates to [RunQueryLazily(GqlQuery, CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_RunQueryLazily_Google_Cloud_Datastore_V1_GqlQuery_Google_Api_Gax_Grpc_CallSettings_)
and calls [GetAllResults()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery#Google_Cloud_Datastore_V1_LazyDatastoreQuery_GetAllResults) on the return value.
**Example**

    DatastoreDb db = DatastoreDb.Create(projectId, namespaceId);
    KeyFactory keyFactory = db.CreateKeyFactory("player");

    // Prepare the data: a player with two game child entities
    Entity player = new Entity
    {
        Key = keyFactory.CreateIncompleteKey(),
        ["name"] = "Sophie"
    };
    Key playerKey = db.Insert(player);
    Entity game1 = new Entity
    {
        Key = playerKey.WithElement(new PathElement { Kind = "game" }),
        ["score"] = 10,
        ["timestamp"] = new DateTime(2017, 2, 16, 8, 35, 0, DateTimeKind.Utc)
    };
    Entity game2 = new Entity
    {
        Key = playerKey.WithElement(new PathElement { Kind = "game" }),
        ["score"] = 25,
        ["timestamp"] = new DateTime(2017, 3, 15, 10, 35, 0, DateTimeKind.Utc)
    };
    db.Insert(game1, game2);

    // Perform a query within a transaction
    using (DatastoreTransaction transaction = db.BeginTransaction())
    {
        // Any query executed in a transaction must at least have an ancestor filter.
        GqlQuery query = new GqlQuery
        {
            QueryString = "SELECT * FROM game WHERE __key__ HAS ANCESTOR @player LIMIT @limit",
            NamedBindings = {
                { "player", playerKey },
                { "limit", 10 }
            }
        };
        DatastoreQueryResults results = db.RunQuery(query);
        // RunQuery fetches all the results into memory in a single call.
        // Constrast this with RunQueryLazily, which merely prepares an enumerable
        // query. Always specify a limit when you use RunQuery, to avoid running
        // out of memory.
        foreach (Entity entity in results.Entities)
        {
            Console.WriteLine(entity);
        }
    }

### RunQuery(Query, CallSettings)

    public virtual DatastoreQueryResults RunQuery(Query query, CallSettings callSettings = null)

Runs the given query eagerly in this transaction, retrieving all results in memory and indicating whether more
results may be available beyond the query's limit. Use this method when your query has a limited
number of results, for example to build a web application which fetches results in pages.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Query` The query to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQueryResults` | The complete query results. |

**Remarks**
Using a transaction ensures that a commit operation will fail if any of the entities returned
by this query have been modified while the transaction is active. Note that modifications performed
as part of this operation are not reflected in the query results.

The default implementation of this method delegates to [RunQueryLazily(Query, CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_RunQueryLazily_Google_Cloud_Datastore_V1_Query_Google_Api_Gax_Grpc_CallSettings_)
and calls [GetAllResults()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery#Google_Cloud_Datastore_V1_LazyDatastoreQuery_GetAllResults) on the return value.
**Example**

    DatastoreDb db = DatastoreDb.Create(projectId, namespaceId);
    KeyFactory keyFactory = db.CreateKeyFactory("player");

    // Prepare the data: a player with two game child entities
    Entity player = new Entity
    {
        Key = keyFactory.CreateIncompleteKey(),
        ["name"] = "Sophie"
    };
    Key playerKey = db.Insert(player);
    Entity game1 = new Entity
    {
        Key = playerKey.WithElement(new PathElement { Kind = "game" }),
        ["score"] = 10,
        ["timestamp"] = new DateTime(2017, 2, 16, 8, 35, 0, DateTimeKind.Utc)
    };
    Entity game2 = new Entity
    {
        Key = playerKey.WithElement(new PathElement { Kind = "game" }),
        ["score"] = 25,
        ["timestamp"] = new DateTime(2017, 3, 15, 10, 35, 0, DateTimeKind.Utc)
    };
    db.Insert(game1, game2);

    // Perform a query within a transaction
    using (DatastoreTransaction transaction = db.BeginTransaction())
    {
        // Any query executed in a transaction must at least have an ancestor filter.
        Query query = new Query("game")
        {
            Filter = Filter.HasAncestor(playerKey),
            Limit = 10
        };
        DatastoreQueryResults results = db.RunQuery(query);
        // RunQuery fetches all the results into memory in a single call.
        // Constrast this with RunQueryLazily, which merely prepares an enumerable
        // query. Always specify a limit when you use RunQuery, to avoid running
        // out of memory.
        foreach (Entity entity in results.Entities)
        {
            Console.WriteLine(entity);
        }
    }

### RunQueryAsync(DatastoreQuery, CallSettings)

    public virtual Task<DatastoreQueryResults> RunQueryAsync(DatastoreQuery query, CallSettings callSettings = null)

Runs the given query eagerly and asynchronously in this transaction, retrieving all results in memory
and indicating whether more results may be available beyond the query's limit. Use this method when your query has a limited
number of results, for example to build a web application which fetches results in pages.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQuery` The query to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQueryResults` | A task representing the asynchronous operation. The result of the task is the complete set of query results. |

**Remarks**
Using a transaction ensures that a commit operation will fail if any of the entities returned
by this query have been modified while the transaction is active. Note that modifications performed
as part of this operation are not reflected in the query results.

The default implementation of this method delegates to [RunQueryLazilyAsync(Query, CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_RunQueryLazilyAsync_Google_Cloud_Datastore_V1_Query_Google_Api_Gax_Grpc_CallSettings_)
and calls [GetAllResultsAsync()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery#Google_Cloud_Datastore_V1_AsyncLazyDatastoreQuery_GetAllResultsAsync) on the return value.

### RunQueryAsync(GqlQuery, CallSettings)

    public virtual Task<DatastoreQueryResults> RunQueryAsync(GqlQuery query, CallSettings callSettings = null)

Runs the given query eagerly and asynchronously in this transaction, retrieving all results in memory and indicating whether more
results may be available beyond the query's limit. Use this method when your query has a limited
number of results, for example to build a web application which fetches results in pages.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.GqlQuery` The query to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQueryResults` | A task representing the asynchronous operation. The result of the task is the complete set of query results. |

**Remarks**
Using a transaction ensures that a commit operation will fail if any of the entities returned
by this query have been modified while the transaction is active. Note that modifications performed
as part of this operation are not reflected in the query results.

The default implementation of this method delegates to [RunQueryLazilyAsync(GqlQuery, CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_RunQueryLazilyAsync_Google_Cloud_Datastore_V1_GqlQuery_Google_Api_Gax_Grpc_CallSettings_)
and calls [GetAllResultsAsync()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery#Google_Cloud_Datastore_V1_AsyncLazyDatastoreQuery_GetAllResultsAsync) on the return value.
**Example**

See [RunQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_RunQuery_Google_Cloud_Datastore_V1_GqlQuery_Google_Api_Gax_Grpc_CallSettings_) for a synchronous example.

### RunQueryAsync(Query, CallSettings)

    public virtual Task<DatastoreQueryResults> RunQueryAsync(Query query, CallSettings callSettings = null)

Runs the given query eagerly and asynchronously in this transaction, retrieving all results in memory
and indicating whether more results may be available beyond the query's limit. Use this method when your query has a limited
number of results, for example to build a web application which fetches results in pages.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Query` The query to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQueryResults` | A task representing the asynchronous operation. The result of the task is the complete set of query results. |

**Remarks**
Using a transaction ensures that a commit operation will fail if any of the entities returned
by this query have been modified while the transaction is active. Note that modifications performed
as part of this operation are not reflected in the query results.

The default implementation of this method delegates to [RunQueryLazilyAsync(Query, CallSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_RunQueryLazilyAsync_Google_Cloud_Datastore_V1_Query_Google_Api_Gax_Grpc_CallSettings_)
and calls [GetAllResultsAsync()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery#Google_Cloud_Datastore_V1_AsyncLazyDatastoreQuery_GetAllResultsAsync) on the return value.
**Example**

See [RunQueryLazily](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_RunQuery_Google_Cloud_Datastore_V1_Query_Google_Api_Gax_Grpc_CallSettings_) for a synchronous example.

### RunQueryLazily(DatastoreQuery, CallSettings)

    public virtual LazyDatastoreQuery RunQueryLazily(DatastoreQuery query, CallSettings callSettings = null)

Lazily executes the given structured query in this transaction.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQuery` The query to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery` | A [LazyDatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery) representing the the lazy query results. |

**Remarks**
Using a transaction ensures that a commit operation will fail if any of the entities returned
by this query have been modified while the transaction is active. Note that modifications performed
as part of this operation are not reflected in the query results.


The results are requested lazily: no API calls will be made until the application starts
iterating over the results. Iterating over the same [LazyDatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery) object
multiple times will execute the query again, potentially returning different results.

### RunQueryLazily(GqlQuery, CallSettings)

    public virtual LazyDatastoreQuery RunQueryLazily(GqlQuery gqlQuery, CallSettings callSettings = null)

Lazily executes the given GQL query in this transaction.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `gqlQuery` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.GqlQuery` The query to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery` | A [LazyDatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery) representing the result of the query. |

**Remarks**
Using a transaction ensures that a commit operation will fail if any of the entities returned
by this query have been modified while the transaction is active. Note that modifications performed
as part of this operation are not reflected in the query results.


The results are requested lazily: no API calls will be made until the application starts
iterating over the results. Iterating over the same [LazyDatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery) object
multiple times will execute the query again, potentially returning different results.
**Example**

    DatastoreDb db = DatastoreDb.Create(projectId, namespaceId);
    KeyFactory keyFactory = db.CreateKeyFactory("player");

    // Prepare the data: a player with two game child entities
    Entity player = new Entity
    {
        Key = keyFactory.CreateIncompleteKey(),
        ["name"] = "Sophie"
    };
    Key playerKey = db.Insert(player);
    Entity game1 = new Entity
    {
        Key = playerKey.WithElement(new PathElement { Kind = "game" }),
        ["score"] = 10,
        ["timestamp"] = new DateTime(2017, 2, 16, 8, 35, 0, DateTimeKind.Utc)
    };
    Entity game2 = new Entity
    {
        Key = playerKey.WithElement(new PathElement { Kind = "game" }),
        ["score"] = 25,
        ["timestamp"] = new DateTime(2017, 3, 15, 10, 35, 0, DateTimeKind.Utc)
    };
    db.Insert(game1, game2);

    // Perform a query within a transaction
    using (DatastoreTransaction transaction = db.BeginTransaction())
    {
        // Any query executed in a transaction must at least have an ancestor filter.
        GqlQuery query = new GqlQuery
        {
            QueryString = "SELECT * FROM game WHERE __key__ HAS ANCESTOR @player",
            NamedBindings = { { "player", playerKey } }
        };
        LazyDatastoreQuery results = db.RunQueryLazily(query);
        // LazyDatastoreQuery implements IEnumerable<Entity>, but you can
        // call AsResponses() to see the raw RPC responses, or
        // GetAllResults() to get all the results into memory, complete with
        // the end cursor and the reason for the query finishing.
        foreach (Entity entity in results)
        {
            Console.WriteLine(entity);
        }
    }

### RunQueryLazily(Query, CallSettings)

    public virtual LazyDatastoreQuery RunQueryLazily(Query query, CallSettings callSettings = null)

Lazily executes the given structured query in this transaction.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Query` The query to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery` | A [LazyDatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery) representing the the lazy query results. |

**Remarks**
Using a transaction ensures that a commit operation will fail if any of the entities returned
by this query have been modified while the transaction is active. Note that modifications performed
as part of this operation are not reflected in the query results.


The results are requested lazily: no API calls will be made until the application starts
iterating over the results. Iterating over the same [LazyDatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery) object
multiple times will execute the query again, potentially returning different results.
**Example**

    DatastoreDb db = DatastoreDb.Create(projectId, namespaceId);
    KeyFactory keyFactory = db.CreateKeyFactory("player");

    // Prepare the data: a player with two game child entities
    Entity player = new Entity
    {
        Key = keyFactory.CreateIncompleteKey(),
        ["name"] = "Sophie"
    };
    Key playerKey = db.Insert(player);
    Entity game1 = new Entity
    {
        Key = playerKey.WithElement(new PathElement { Kind = "game" }),
        ["score"] = 10,
        ["timestamp"] = new DateTime(2017, 2, 16, 8, 35, 0, DateTimeKind.Utc)
    };
    Entity game2 = new Entity
    {
        Key = playerKey.WithElement(new PathElement { Kind = "game" }),
        ["score"] = 25,
        ["timestamp"] = new DateTime(2017, 3, 15, 10, 35, 0, DateTimeKind.Utc)
    };
    db.Insert(game1, game2);

    // Perform a query within a transaction
    using (DatastoreTransaction transaction = db.BeginTransaction())
    {
        // Any query executed in a transaction must at least have an ancestor filter.
        Query query = new Query("game")
        {
            Filter = Filter.HasAncestor(playerKey)
        };
        LazyDatastoreQuery results = db.RunQueryLazily(query);
        // LazyDatastoreQuery implements IEnumerable<Entity>, but you can
        // call AsResponses() to see the raw RPC responses, or
        // GetAllResults() to get all the results into memory, complete with
        // the end cursor and the reason for the query finishing.
        foreach (Entity entity in results)
        {
            Console.WriteLine(entity);
        }
    }

### RunQueryLazilyAsync(DatastoreQuery, CallSettings)

    public virtual AsyncLazyDatastoreQuery RunQueryLazilyAsync(DatastoreQuery query, CallSettings callSettings = null)

Lazily executes the given structured query in this transaction for asynchronous consumption.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreQuery` The query to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery` | An [AsyncLazyDatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery) representing the result of the query. |

**Remarks**
Using a transaction ensures that a commit operation will fail if any of the entities returned
by this query have been modified while the transaction is active. Note that modifications performed
as part of this operation are not reflected in the query results.


The results are requested lazily: no API calls will be made until the application starts
iterating over the results. Iterating over the same [LazyDatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery) object
multiple times will execute the query again, potentially returning different results.

### RunQueryLazilyAsync(GqlQuery, CallSettings)

    public virtual AsyncLazyDatastoreQuery RunQueryLazilyAsync(GqlQuery gqlQuery, CallSettings callSettings = null)

Lazily executes the given structured query in this transaction for asynchronous consumption.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `gqlQuery` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.GqlQuery` The query to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery` | An [AsyncLazyDatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery) representing the result of the query. |

**Remarks**
Using a transaction ensures that a commit operation will fail if any of the entities returned
by this query have been modified while the transaction is active. Note that modifications performed
as part of this operation are not reflected in the query results.


The results are requested lazily: no API calls will be made until the application starts
iterating over the results. Iterating over the same [LazyDatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery) object
multiple times will execute the query again, potentially returning different results.
**Example**

See [RunQueryLazily](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_RunQueryLazily_Google_Cloud_Datastore_V1_GqlQuery_Google_Api_Gax_Grpc_CallSettings_) for a synchronous example.

### RunQueryLazilyAsync(Query, CallSettings)

    public virtual AsyncLazyDatastoreQuery RunQueryLazilyAsync(Query query, CallSettings callSettings = null)

Lazily executes the given structured query in this transaction for asynchronous consumption.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Query` The query to execute. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to RPC calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery` | An [AsyncLazyDatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery) representing the result of the query. |

**Remarks**
Using a transaction ensures that a commit operation will fail if any of the entities returned
by this query have been modified while the transaction is active. Note that modifications performed
as part of this operation are not reflected in the query results.


The results are requested lazily: no API calls will be made until the application starts
iterating over the results. Iterating over the same [LazyDatastoreQuery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery) object
multiple times will execute the query again, potentially returning different results.
**Example**

See [RunQueryLazily](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_RunQueryLazily_Google_Cloud_Datastore_V1_Query_Google_Api_Gax_Grpc_CallSettings_) for a synchronous example.

### Update(params Entity\[\])

    public virtual void Update(params Entity[] entities)

Adds update operations for all the specified keys to this transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `entities` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` The entities to update. Must not be null. |

**Remarks** This method delegates to [Update(IEnumerable\<Entity\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Update_System_Collections_Generic_IEnumerable_Google_Cloud_Datastore_V1_Entity__).
**Example**

    DatastoreDb db = DatastoreDb.Create(projectId, namespaceId);
    KeyFactory keyFactory = db.CreateKeyFactory("book");
    Entity book = new Entity
    {
        Key = keyFactory.CreateIncompleteKey(),
        ["author"] = "Harper Lee",
        ["title"] = "Tequila Mockingbird",
        ["publication_date"] = new DateTime(1960, 7, 11, 0, 0, 0, DateTimeKind.Utc),
        ["genres"] = new[] { "Southern drama", "Courtroom drama", "Bildungsroman" }
    };
    db.Insert(book);

    using (DatastoreTransaction transaction = db.BeginTransaction())
    {
        // Correct the typo in memory
        book["title"] = "To Kill a Mockingbird";
        // This adds the entity to a collection of mutations in memory: nothing
        // is sent to the server.
        transaction.Update(book);
        // Without the Commit call, the transaction will automatically
        // be rolled back. The Commit call performs all the mutations
        // within the transaction.
        transaction.Commit();
    }

### Update(IEnumerable\<Entity\>)

    public virtual void Update(IEnumerable<Entity> entities)

Adds update operations for all the specified keys to this transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `entities` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` The entities to update. Must not be null. |

**Example**

See [Update](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Update_Google_Cloud_Datastore_V1_Entity___) for an example using an alternative overload.

### Upsert(params Entity\[\])

    public virtual void Upsert(params Entity[] entities)

Adds upsert operations for all the specified keys to this transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `entities` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` The entities to upsert. Must not be null. |

**Remarks** This method delegates to [Upsert(IEnumerable\<Entity\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Upsert_System_Collections_Generic_IEnumerable_Google_Cloud_Datastore_V1_Entity__).
**Example**

    DatastoreDb db = DatastoreDb.Create(projectId, namespaceId);
    KeyFactory keyFactory = db.CreateKeyFactory("book");
    Entity book1 = new Entity
    {
        Key = keyFactory.CreateIncompleteKey(),
        ["author"] = "Harper Lee",
        ["title"] = "Tequila Mockingbird",
        ["publication_date"] = new DateTime(1960, 7, 11, 0, 0, 0, DateTimeKind.Utc),
        ["genres"] = new[] { "Southern drama", "Courtroom drama", "Bildungsroman" }
    };
    db.Insert(book1);

    using (DatastoreTransaction transaction = db.BeginTransaction())
    {
        // Correct the typo in memory
        book1["title"] = "To Kill a Mockingbird";

        Entity book2 = new Entity
        {
            Key = keyFactory.CreateIncompleteKey(),
            ["author"] = "Charlotte Brontë",
            ["title"] = "Jane Eyre",
            ["publication_date"] = new DateTime(1847, 10, 16, 0, 0, 0, DateTimeKind.Utc),
            ["genres"] = new[] { "Gothic", "Romance", "Bildungsroman" }
        };

        // This adds the entities to a collection of mutations in memory: nothing
        // is sent to the server.
        transaction.Upsert(book1, book2);
        // Without the Commit call, the transaction will automatically
        // be rolled back. The Commit call performs all the mutations
        // within the transaction.
        transaction.Commit();
    }

### Upsert(IEnumerable\<Entity\>)

    public virtual void Upsert(IEnumerable<Entity> entities)

Adds upsert operations for all the specified keys to this transaction.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `entities` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity` The entities to upsert. Must not be null. |

**Example**

See [Upsert](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreTransaction#Google_Cloud_Datastore_V1_DatastoreTransaction_Upsert_Google_Cloud_Datastore_V1_Entity___) for an example using an alternative overload.