Google Cloud Datastore v1 API - Class DatastoreClient (4.10.0)

public abstract class DatastoreClient

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

Datastore client wrapper, for convenient use.

Inheritance

object > DatastoreClient

Derived Types

Namespace

Google.Cloud.Datastore.V1

Assembly

Google.Cloud.Datastore.V1.dll

Remarks

Each RPC normalizes the partition IDs of the keys in its input entities, and always returns entities with keys with normalized partition IDs. This applies to all keys and entities, including those in values, except keys with both an empty path and an empty or unset partition ID. Normalization of input keys sets the project ID (if not already set) to the project ID from the request.

Properties

DefaultEndpoint

public static string DefaultEndpoint { get; }

The default endpoint for the Datastore service, which is a host of "datastore.googleapis.com" and a port of 443.

Property Value
TypeDescription
string

DefaultScopes

public static IReadOnlyList<string> DefaultScopes { get; }

The default Datastore scopes.

Property Value
TypeDescription
IReadOnlyListstring
Remarks

GrpcClient

public virtual Datastore.DatastoreClient GrpcClient { get; }

The underlying gRPC Datastore client

Property Value
TypeDescription
DatastoreDatastoreClient

ServiceMetadata

public static ServiceMetadata ServiceMetadata { get; }

The service metadata associated with this client type.

Property Value
TypeDescription
ServiceMetadata

Methods

AllocateIds(AllocateIdsRequest, CallSettings)

public virtual AllocateIdsResponse AllocateIds(AllocateIdsRequest request, CallSettings callSettings = null)

Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.

Parameters
NameDescription
requestAllocateIdsRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
AllocateIdsResponse

The RPC response.

Example
// Create client
DatastoreClient datastoreClient = DatastoreClient.Create();
// Initialize request argument(s)
AllocateIdsRequest request = new AllocateIdsRequest
{
    Keys = { new Key(), },
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
AllocateIdsResponse response = datastoreClient.AllocateIds(request);

AllocateIds(string, IEnumerable<Key>, CallSettings)

public virtual AllocateIdsResponse AllocateIds(string projectId, IEnumerable<Key> keys, CallSettings callSettings = null)

Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

keysIEnumerableKey

Required. A list of keys with incomplete key paths for which to allocate IDs. No key may be reserved/read-only.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
AllocateIdsResponse

The RPC response.

Example
DatastoreClient client = DatastoreClient.Create();
KeyFactory keyFactory = new KeyFactory(projectId, namespaceId, "message");
AllocateIdsResponse response = client.AllocateIds(projectId,
    new[] { keyFactory.CreateIncompleteKey(), keyFactory.CreateIncompleteKey() }
);
Entity entity1 = new Entity { Key = response.Keys[0], ["text"] = "Text 1" };
Entity entity2 = new Entity { Key = response.Keys[1], ["text"] = "Text 2" };

AllocateIdsAsync(AllocateIdsRequest, CallSettings)

public virtual Task<AllocateIdsResponse> AllocateIdsAsync(AllocateIdsRequest request, CallSettings callSettings = null)

Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.

Parameters
NameDescription
requestAllocateIdsRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskAllocateIdsResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
AllocateIdsRequest request = new AllocateIdsRequest
{
    Keys = { new Key(), },
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
AllocateIdsResponse response = await datastoreClient.AllocateIdsAsync(request);

AllocateIdsAsync(AllocateIdsRequest, CancellationToken)

public virtual Task<AllocateIdsResponse> AllocateIdsAsync(AllocateIdsRequest request, CancellationToken cancellationToken)

Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.

Parameters
NameDescription
requestAllocateIdsRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskAllocateIdsResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
AllocateIdsRequest request = new AllocateIdsRequest
{
    Keys = { new Key(), },
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
AllocateIdsResponse response = await datastoreClient.AllocateIdsAsync(request);

AllocateIdsAsync(string, IEnumerable<Key>, CallSettings)

public virtual Task<AllocateIdsResponse> AllocateIdsAsync(string projectId, IEnumerable<Key> keys, CallSettings callSettings = null)

Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

keysIEnumerableKey

Required. A list of keys with incomplete key paths for which to allocate IDs. No key may be reserved/read-only.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskAllocateIdsResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
IEnumerable<Key> keys = new Key[] { new Key(), };
// Make the request
AllocateIdsResponse response = await datastoreClient.AllocateIdsAsync(projectId, keys);

AllocateIdsAsync(string, IEnumerable<Key>, CancellationToken)

public virtual Task<AllocateIdsResponse> AllocateIdsAsync(string projectId, IEnumerable<Key> keys, CancellationToken cancellationToken)

Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

keysIEnumerableKey

Required. A list of keys with incomplete key paths for which to allocate IDs. No key may be reserved/read-only.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskAllocateIdsResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
IEnumerable<Key> keys = new Key[] { new Key(), };
// Make the request
AllocateIdsResponse response = await datastoreClient.AllocateIdsAsync(projectId, keys);

BeginTransaction(BeginTransactionRequest, CallSettings)

public virtual BeginTransactionResponse BeginTransaction(BeginTransactionRequest request, CallSettings callSettings = null)

Begins a new transaction.

Parameters
NameDescription
requestBeginTransactionRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
BeginTransactionResponse

The RPC response.

Example
// Create client
DatastoreClient datastoreClient = DatastoreClient.Create();
// Initialize request argument(s)
BeginTransactionRequest request = new BeginTransactionRequest
{
    ProjectId = "",
    DatabaseId = "",
    TransactionOptions = new TransactionOptions(),
};
// Make the request
BeginTransactionResponse response = datastoreClient.BeginTransaction(request);

BeginTransaction(string, CallSettings)

public virtual BeginTransactionResponse BeginTransaction(string projectId, CallSettings callSettings = null)

Begins a new transaction.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
BeginTransactionResponse

The RPC response.

Example
// Create client
DatastoreClient datastoreClient = DatastoreClient.Create();
// Initialize request argument(s)
string projectId = "";
// Make the request
BeginTransactionResponse response = datastoreClient.BeginTransaction(projectId);

BeginTransactionAsync(BeginTransactionRequest, CallSettings)

public virtual Task<BeginTransactionResponse> BeginTransactionAsync(BeginTransactionRequest request, CallSettings callSettings = null)

Begins a new transaction.

Parameters
NameDescription
requestBeginTransactionRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskBeginTransactionResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
BeginTransactionRequest request = new BeginTransactionRequest
{
    ProjectId = "",
    DatabaseId = "",
    TransactionOptions = new TransactionOptions(),
};
// Make the request
BeginTransactionResponse response = await datastoreClient.BeginTransactionAsync(request);

BeginTransactionAsync(BeginTransactionRequest, CancellationToken)

public virtual Task<BeginTransactionResponse> BeginTransactionAsync(BeginTransactionRequest request, CancellationToken cancellationToken)

Begins a new transaction.

Parameters
NameDescription
requestBeginTransactionRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskBeginTransactionResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
BeginTransactionRequest request = new BeginTransactionRequest
{
    ProjectId = "",
    DatabaseId = "",
    TransactionOptions = new TransactionOptions(),
};
// Make the request
BeginTransactionResponse response = await datastoreClient.BeginTransactionAsync(request);

BeginTransactionAsync(string, CallSettings)

public virtual Task<BeginTransactionResponse> BeginTransactionAsync(string projectId, CallSettings callSettings = null)

Begins a new transaction.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskBeginTransactionResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
// Make the request
BeginTransactionResponse response = await datastoreClient.BeginTransactionAsync(projectId);

BeginTransactionAsync(string, CancellationToken)

public virtual Task<BeginTransactionResponse> BeginTransactionAsync(string projectId, CancellationToken cancellationToken)

Begins a new transaction.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskBeginTransactionResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
// Make the request
BeginTransactionResponse response = await datastoreClient.BeginTransactionAsync(projectId);

Commit(CommitRequest, CallSettings)

public virtual CommitResponse Commit(CommitRequest request, CallSettings callSettings = null)

Commits a transaction, optionally creating, deleting or modifying some entities.

Parameters
NameDescription
requestCommitRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
CommitResponse

The RPC response.

Example
// Create client
DatastoreClient datastoreClient = DatastoreClient.Create();
// Initialize request argument(s)
CommitRequest request = new CommitRequest
{
    Transaction = ByteString.Empty,
    Mode = CommitRequest.Types.Mode.Unspecified,
    Mutations = { new Mutation(), },
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
CommitResponse response = datastoreClient.Commit(request);

Commit(string, Mode, ByteString, IEnumerable<Mutation>, CallSettings)

public virtual CommitResponse Commit(string projectId, CommitRequest.Types.Mode mode, ByteString transaction, IEnumerable<Mutation> mutations, CallSettings callSettings = null)

Commits a transaction, optionally creating, deleting or modifying some entities.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

modeCommitRequestTypesMode

The type of commit to perform. Defaults to TRANSACTIONAL.

transactionByteString

The identifier of the transaction associated with the commit. A transaction identifier is returned by a call to [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].

mutationsIEnumerableMutation

The mutations to perform.

When mode is TRANSACTIONAL, mutations affecting a single entity are applied in order. The following sequences of mutations affecting a single entity are not permitted in a single Commit request:

  • insert followed by insert
  • update followed by insert
  • upsert followed by insert
  • delete followed by update

When mode is NON_TRANSACTIONAL, no two mutations may affect a single entity.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
CommitResponse

The RPC response.

Example
// Create client
DatastoreClient datastoreClient = DatastoreClient.Create();
// Initialize request argument(s)
string projectId = "";
CommitRequest.Types.Mode mode = CommitRequest.Types.Mode.Unspecified;
ByteString transaction = ByteString.Empty;
IEnumerable<Mutation> mutations = new Mutation[] { new Mutation(), };
// Make the request
CommitResponse response = datastoreClient.Commit(projectId, mode, transaction, mutations);

Commit(string, Mode, IEnumerable<Mutation>, CallSettings)

public virtual CommitResponse Commit(string projectId, CommitRequest.Types.Mode mode, IEnumerable<Mutation> mutations, CallSettings callSettings = null)

Commits a transaction, optionally creating, deleting or modifying some entities.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

modeCommitRequestTypesMode

The type of commit to perform. Defaults to TRANSACTIONAL.

mutationsIEnumerableMutation

The mutations to perform.

When mode is TRANSACTIONAL, mutations affecting a single entity are applied in order. The following sequences of mutations affecting a single entity are not permitted in a single Commit request:

  • insert followed by insert
  • update followed by insert
  • upsert followed by insert
  • delete followed by update

When mode is NON_TRANSACTIONAL, no two mutations may affect a single entity.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
CommitResponse

The RPC response.

Example
// Create client
DatastoreClient datastoreClient = DatastoreClient.Create();
// Initialize request argument(s)
string projectId = "";
CommitRequest.Types.Mode mode = CommitRequest.Types.Mode.Unspecified;
IEnumerable<Mutation> mutations = new Mutation[] { new Mutation(), };
// Make the request
CommitResponse response = datastoreClient.Commit(projectId, mode, mutations);

CommitAsync(CommitRequest, CallSettings)

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

Commits a transaction, optionally creating, deleting or modifying some entities.

Parameters
NameDescription
requestCommitRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskCommitResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
CommitRequest request = new CommitRequest
{
    Transaction = ByteString.Empty,
    Mode = CommitRequest.Types.Mode.Unspecified,
    Mutations = { new Mutation(), },
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
CommitResponse response = await datastoreClient.CommitAsync(request);

CommitAsync(CommitRequest, CancellationToken)

public virtual Task<CommitResponse> CommitAsync(CommitRequest request, CancellationToken cancellationToken)

Commits a transaction, optionally creating, deleting or modifying some entities.

Parameters
NameDescription
requestCommitRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskCommitResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
CommitRequest request = new CommitRequest
{
    Transaction = ByteString.Empty,
    Mode = CommitRequest.Types.Mode.Unspecified,
    Mutations = { new Mutation(), },
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
CommitResponse response = await datastoreClient.CommitAsync(request);

CommitAsync(string, Mode, ByteString, IEnumerable<Mutation>, CallSettings)

public virtual Task<CommitResponse> CommitAsync(string projectId, CommitRequest.Types.Mode mode, ByteString transaction, IEnumerable<Mutation> mutations, CallSettings callSettings = null)

Commits a transaction, optionally creating, deleting or modifying some entities.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

modeCommitRequestTypesMode

The type of commit to perform. Defaults to TRANSACTIONAL.

transactionByteString

The identifier of the transaction associated with the commit. A transaction identifier is returned by a call to [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].

mutationsIEnumerableMutation

The mutations to perform.

When mode is TRANSACTIONAL, mutations affecting a single entity are applied in order. The following sequences of mutations affecting a single entity are not permitted in a single Commit request:

  • insert followed by insert
  • update followed by insert
  • upsert followed by insert
  • delete followed by update

When mode is NON_TRANSACTIONAL, no two mutations may affect a single entity.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskCommitResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
CommitRequest.Types.Mode mode = CommitRequest.Types.Mode.Unspecified;
ByteString transaction = ByteString.Empty;
IEnumerable<Mutation> mutations = new Mutation[] { new Mutation(), };
// Make the request
CommitResponse response = await datastoreClient.CommitAsync(projectId, mode, transaction, mutations);

CommitAsync(string, Mode, ByteString, IEnumerable<Mutation>, CancellationToken)

public virtual Task<CommitResponse> CommitAsync(string projectId, CommitRequest.Types.Mode mode, ByteString transaction, IEnumerable<Mutation> mutations, CancellationToken cancellationToken)

Commits a transaction, optionally creating, deleting or modifying some entities.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

modeCommitRequestTypesMode

The type of commit to perform. Defaults to TRANSACTIONAL.

transactionByteString

The identifier of the transaction associated with the commit. A transaction identifier is returned by a call to [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].

mutationsIEnumerableMutation

The mutations to perform.

When mode is TRANSACTIONAL, mutations affecting a single entity are applied in order. The following sequences of mutations affecting a single entity are not permitted in a single Commit request:

  • insert followed by insert
  • update followed by insert
  • upsert followed by insert
  • delete followed by update

When mode is NON_TRANSACTIONAL, no two mutations may affect a single entity.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskCommitResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
CommitRequest.Types.Mode mode = CommitRequest.Types.Mode.Unspecified;
ByteString transaction = ByteString.Empty;
IEnumerable<Mutation> mutations = new Mutation[] { new Mutation(), };
// Make the request
CommitResponse response = await datastoreClient.CommitAsync(projectId, mode, transaction, mutations);

CommitAsync(string, Mode, IEnumerable<Mutation>, CallSettings)

public virtual Task<CommitResponse> CommitAsync(string projectId, CommitRequest.Types.Mode mode, IEnumerable<Mutation> mutations, CallSettings callSettings = null)

Commits a transaction, optionally creating, deleting or modifying some entities.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

modeCommitRequestTypesMode

The type of commit to perform. Defaults to TRANSACTIONAL.

mutationsIEnumerableMutation

The mutations to perform.

When mode is TRANSACTIONAL, mutations affecting a single entity are applied in order. The following sequences of mutations affecting a single entity are not permitted in a single Commit request:

  • insert followed by insert
  • update followed by insert
  • upsert followed by insert
  • delete followed by update

When mode is NON_TRANSACTIONAL, no two mutations may affect a single entity.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskCommitResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
CommitRequest.Types.Mode mode = CommitRequest.Types.Mode.Unspecified;
IEnumerable<Mutation> mutations = new Mutation[] { new Mutation(), };
// Make the request
CommitResponse response = await datastoreClient.CommitAsync(projectId, mode, mutations);

CommitAsync(string, Mode, IEnumerable<Mutation>, CancellationToken)

public virtual Task<CommitResponse> CommitAsync(string projectId, CommitRequest.Types.Mode mode, IEnumerable<Mutation> mutations, CancellationToken cancellationToken)

Commits a transaction, optionally creating, deleting or modifying some entities.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

modeCommitRequestTypesMode

The type of commit to perform. Defaults to TRANSACTIONAL.

mutationsIEnumerableMutation

The mutations to perform.

When mode is TRANSACTIONAL, mutations affecting a single entity are applied in order. The following sequences of mutations affecting a single entity are not permitted in a single Commit request:

  • insert followed by insert
  • update followed by insert
  • upsert followed by insert
  • delete followed by update

When mode is NON_TRANSACTIONAL, no two mutations may affect a single entity.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskCommitResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
CommitRequest.Types.Mode mode = CommitRequest.Types.Mode.Unspecified;
IEnumerable<Mutation> mutations = new Mutation[] { new Mutation(), };
// Make the request
CommitResponse response = await datastoreClient.CommitAsync(projectId, mode, mutations);

Create()

public static DatastoreClient Create()

Synchronously creates a DatastoreClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use DatastoreClientBuilder.

Returns
TypeDescription
DatastoreClient

The created DatastoreClient.

CreateAsync(CancellationToken)

public static Task<DatastoreClient> CreateAsync(CancellationToken cancellationToken = default)

Asynchronously creates a DatastoreClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use DatastoreClientBuilder.

Parameter
NameDescription
cancellationTokenCancellationToken

The CancellationToken to use while creating the client.

Returns
TypeDescription
TaskDatastoreClient

The task representing the created DatastoreClient.

Lookup(LookupRequest, CallSettings)

public virtual LookupResponse Lookup(LookupRequest request, CallSettings callSettings = null)

Looks up entities by key.

Parameters
NameDescription
requestLookupRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
LookupResponse

The RPC response.

Example
// Create client
DatastoreClient datastoreClient = DatastoreClient.Create();
// Initialize request argument(s)
LookupRequest request = new LookupRequest
{
    ReadOptions = new ReadOptions(),
    Keys = { new Key(), },
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
LookupResponse response = datastoreClient.Lookup(request);

Lookup(string, ReadOptions, IEnumerable<Key>, CallSettings)

public virtual LookupResponse Lookup(string projectId, ReadOptions readOptions, IEnumerable<Key> keys, CallSettings callSettings = null)

Looks up entities by key.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

readOptionsReadOptions

The options for this lookup request.

keysIEnumerableKey

Required. Keys of entities to look up.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
LookupResponse

The RPC response.

Example
KeyFactory keyFactory = new KeyFactory(projectId, namespaceId, "book");
Key key1 = keyFactory.CreateKey("pride_and_prejudice");
Key key2 = keyFactory.CreateKey("not_present");

DatastoreClient client = DatastoreClient.Create();
LookupResponse response = client.Lookup(
    projectId,
    new ReadOptions { ReadConsistency = ReadConsistency.Strong },
    new[] { key1, key2 });
Console.WriteLine($"Found: {response.Found.Count}");
Console.WriteLine($"Deferred: {response.Deferred.Count}");
Console.WriteLine($"Missing: {response.Missing.Count}");

LookupAsync(LookupRequest, CallSettings)

public virtual Task<LookupResponse> LookupAsync(LookupRequest request, CallSettings callSettings = null)

Looks up entities by key.

Parameters
NameDescription
requestLookupRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskLookupResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
LookupRequest request = new LookupRequest
{
    ReadOptions = new ReadOptions(),
    Keys = { new Key(), },
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
LookupResponse response = await datastoreClient.LookupAsync(request);

LookupAsync(LookupRequest, CancellationToken)

public virtual Task<LookupResponse> LookupAsync(LookupRequest request, CancellationToken cancellationToken)

Looks up entities by key.

Parameters
NameDescription
requestLookupRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskLookupResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
LookupRequest request = new LookupRequest
{
    ReadOptions = new ReadOptions(),
    Keys = { new Key(), },
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
LookupResponse response = await datastoreClient.LookupAsync(request);

LookupAsync(string, ReadOptions, IEnumerable<Key>, CallSettings)

public virtual Task<LookupResponse> LookupAsync(string projectId, ReadOptions readOptions, IEnumerable<Key> keys, CallSettings callSettings = null)

Looks up entities by key.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

readOptionsReadOptions

The options for this lookup request.

keysIEnumerableKey

Required. Keys of entities to look up.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskLookupResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
ReadOptions readOptions = new ReadOptions();
IEnumerable<Key> keys = new Key[] { new Key(), };
// Make the request
LookupResponse response = await datastoreClient.LookupAsync(projectId, readOptions, keys);

LookupAsync(string, ReadOptions, IEnumerable<Key>, CancellationToken)

public virtual Task<LookupResponse> LookupAsync(string projectId, ReadOptions readOptions, IEnumerable<Key> keys, CancellationToken cancellationToken)

Looks up entities by key.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

readOptionsReadOptions

The options for this lookup request.

keysIEnumerableKey

Required. Keys of entities to look up.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskLookupResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
ReadOptions readOptions = new ReadOptions();
IEnumerable<Key> keys = new Key[] { new Key(), };
// Make the request
LookupResponse response = await datastoreClient.LookupAsync(projectId, readOptions, keys);

ReserveIds(ReserveIdsRequest, CallSettings)

public virtual ReserveIdsResponse ReserveIds(ReserveIdsRequest request, CallSettings callSettings = null)

Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.

Parameters
NameDescription
requestReserveIdsRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
ReserveIdsResponse

The RPC response.

Example
// Create client
DatastoreClient datastoreClient = DatastoreClient.Create();
// Initialize request argument(s)
ReserveIdsRequest request = new ReserveIdsRequest
{
    Keys = { new Key(), },
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
ReserveIdsResponse response = datastoreClient.ReserveIds(request);

ReserveIds(string, IEnumerable<Key>, CallSettings)

public virtual ReserveIdsResponse ReserveIds(string projectId, IEnumerable<Key> keys, CallSettings callSettings = null)

Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

keysIEnumerableKey

Required. A list of keys with complete key paths whose numeric IDs should not be auto-allocated.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
ReserveIdsResponse

The RPC response.

Example
// Create client
DatastoreClient datastoreClient = DatastoreClient.Create();
// Initialize request argument(s)
string projectId = "";
IEnumerable<Key> keys = new Key[] { new Key(), };
// Make the request
ReserveIdsResponse response = datastoreClient.ReserveIds(projectId, keys);

ReserveIdsAsync(ReserveIdsRequest, CallSettings)

public virtual Task<ReserveIdsResponse> ReserveIdsAsync(ReserveIdsRequest request, CallSettings callSettings = null)

Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.

Parameters
NameDescription
requestReserveIdsRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskReserveIdsResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
ReserveIdsRequest request = new ReserveIdsRequest
{
    Keys = { new Key(), },
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
ReserveIdsResponse response = await datastoreClient.ReserveIdsAsync(request);

ReserveIdsAsync(ReserveIdsRequest, CancellationToken)

public virtual Task<ReserveIdsResponse> ReserveIdsAsync(ReserveIdsRequest request, CancellationToken cancellationToken)

Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.

Parameters
NameDescription
requestReserveIdsRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskReserveIdsResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
ReserveIdsRequest request = new ReserveIdsRequest
{
    Keys = { new Key(), },
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
ReserveIdsResponse response = await datastoreClient.ReserveIdsAsync(request);

ReserveIdsAsync(string, IEnumerable<Key>, CallSettings)

public virtual Task<ReserveIdsResponse> ReserveIdsAsync(string projectId, IEnumerable<Key> keys, CallSettings callSettings = null)

Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

keysIEnumerableKey

Required. A list of keys with complete key paths whose numeric IDs should not be auto-allocated.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskReserveIdsResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
IEnumerable<Key> keys = new Key[] { new Key(), };
// Make the request
ReserveIdsResponse response = await datastoreClient.ReserveIdsAsync(projectId, keys);

ReserveIdsAsync(string, IEnumerable<Key>, CancellationToken)

public virtual Task<ReserveIdsResponse> ReserveIdsAsync(string projectId, IEnumerable<Key> keys, CancellationToken cancellationToken)

Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

keysIEnumerableKey

Required. A list of keys with complete key paths whose numeric IDs should not be auto-allocated.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskReserveIdsResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
IEnumerable<Key> keys = new Key[] { new Key(), };
// Make the request
ReserveIdsResponse response = await datastoreClient.ReserveIdsAsync(projectId, keys);

Rollback(RollbackRequest, CallSettings)

public virtual RollbackResponse Rollback(RollbackRequest request, CallSettings callSettings = null)

Rolls back a transaction.

Parameters
NameDescription
requestRollbackRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
RollbackResponse

The RPC response.

Example
// Create client
DatastoreClient datastoreClient = DatastoreClient.Create();
// Initialize request argument(s)
RollbackRequest request = new RollbackRequest
{
    Transaction = ByteString.Empty,
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
RollbackResponse response = datastoreClient.Rollback(request);

Rollback(string, ByteString, CallSettings)

public virtual RollbackResponse Rollback(string projectId, ByteString transaction, CallSettings callSettings = null)

Rolls back a transaction.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

transactionByteString

Required. The transaction identifier, returned by a call to [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
RollbackResponse

The RPC response.

Example
// Create client
DatastoreClient datastoreClient = DatastoreClient.Create();
// Initialize request argument(s)
string projectId = "";
ByteString transaction = ByteString.Empty;
// Make the request
RollbackResponse response = datastoreClient.Rollback(projectId, transaction);

RollbackAsync(RollbackRequest, CallSettings)

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

Rolls back a transaction.

Parameters
NameDescription
requestRollbackRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskRollbackResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
RollbackRequest request = new RollbackRequest
{
    Transaction = ByteString.Empty,
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
RollbackResponse response = await datastoreClient.RollbackAsync(request);

RollbackAsync(RollbackRequest, CancellationToken)

public virtual Task<RollbackResponse> RollbackAsync(RollbackRequest request, CancellationToken cancellationToken)

Rolls back a transaction.

Parameters
NameDescription
requestRollbackRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskRollbackResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
RollbackRequest request = new RollbackRequest
{
    Transaction = ByteString.Empty,
    ProjectId = "",
    DatabaseId = "",
};
// Make the request
RollbackResponse response = await datastoreClient.RollbackAsync(request);

RollbackAsync(string, ByteString, CallSettings)

public virtual Task<RollbackResponse> RollbackAsync(string projectId, ByteString transaction, CallSettings callSettings = null)

Rolls back a transaction.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

transactionByteString

Required. The transaction identifier, returned by a call to [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskRollbackResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
ByteString transaction = ByteString.Empty;
// Make the request
RollbackResponse response = await datastoreClient.RollbackAsync(projectId, transaction);

RollbackAsync(string, ByteString, CancellationToken)

public virtual Task<RollbackResponse> RollbackAsync(string projectId, ByteString transaction, CancellationToken cancellationToken)

Rolls back a transaction.

Parameters
NameDescription
projectIdstring

Required. The ID of the project against which to make the request.

transactionByteString

Required. The transaction identifier, returned by a call to [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskRollbackResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
string projectId = "";
ByteString transaction = ByteString.Empty;
// Make the request
RollbackResponse response = await datastoreClient.RollbackAsync(projectId, transaction);

RunAggregationQuery(RunAggregationQueryRequest, CallSettings)

public virtual RunAggregationQueryResponse RunAggregationQuery(RunAggregationQueryRequest request, CallSettings callSettings = null)

Runs an aggregation query.

Parameters
NameDescription
requestRunAggregationQueryRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
RunAggregationQueryResponse

The RPC response.

Example
// Create client
DatastoreClient datastoreClient = DatastoreClient.Create();
// Initialize request argument(s)
RunAggregationQueryRequest request = new RunAggregationQueryRequest
{
    ReadOptions = new ReadOptions(),
    PartitionId = new PartitionId(),
    AggregationQuery = new AggregationQuery(),
    ProjectId = "",
    DatabaseId = "",
    ExplainOptions = new ExplainOptions(),
};
// Make the request
RunAggregationQueryResponse response = datastoreClient.RunAggregationQuery(request);

RunAggregationQueryAsync(RunAggregationQueryRequest, CallSettings)

public virtual Task<RunAggregationQueryResponse> RunAggregationQueryAsync(RunAggregationQueryRequest request, CallSettings callSettings = null)

Runs an aggregation query.

Parameters
NameDescription
requestRunAggregationQueryRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskRunAggregationQueryResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
RunAggregationQueryRequest request = new RunAggregationQueryRequest
{
    ReadOptions = new ReadOptions(),
    PartitionId = new PartitionId(),
    AggregationQuery = new AggregationQuery(),
    ProjectId = "",
    DatabaseId = "",
    ExplainOptions = new ExplainOptions(),
};
// Make the request
RunAggregationQueryResponse response = await datastoreClient.RunAggregationQueryAsync(request);

RunAggregationQueryAsync(RunAggregationQueryRequest, CancellationToken)

public virtual Task<RunAggregationQueryResponse> RunAggregationQueryAsync(RunAggregationQueryRequest request, CancellationToken cancellationToken)

Runs an aggregation query.

Parameters
NameDescription
requestRunAggregationQueryRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskRunAggregationQueryResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
RunAggregationQueryRequest request = new RunAggregationQueryRequest
{
    ReadOptions = new ReadOptions(),
    PartitionId = new PartitionId(),
    AggregationQuery = new AggregationQuery(),
    ProjectId = "",
    DatabaseId = "",
    ExplainOptions = new ExplainOptions(),
};
// Make the request
RunAggregationQueryResponse response = await datastoreClient.RunAggregationQueryAsync(request);

RunQuery(RunQueryRequest, CallSettings)

public virtual RunQueryResponse RunQuery(RunQueryRequest request, CallSettings callSettings = null)

Queries for entities.

Parameters
NameDescription
requestRunQueryRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
RunQueryResponse

The RPC response.

Example
DatastoreClient client = DatastoreClient.Create();

RunQueryRequest request = new RunQueryRequest
{
    ProjectId = projectId,
    PartitionId = partitionId,
    ReadOptions = new ReadOptions { ReadConsistency = ReadConsistency.Eventual },
};
// Structured query
request.Query = new Query("book")
{
    Filter = Filter.Equal("author", "Jane Austen")
};
RunQueryResponse response = client.RunQuery(request);
foreach (EntityResult result in response.Batch.EntityResults)
{
    Console.WriteLine(result.Entity);
}

// Equivalent GQL query
request.GqlQuery = new GqlQuery
{
    QueryString = "SELECT * FROM book WHERE author = @author",
    NamedBindings = { { "author", "Jane Austen" } },
};
foreach (EntityResult result in response.Batch.EntityResults)
{
    Console.WriteLine(result.Entity);
}

RunQueryAsync(RunQueryRequest, CallSettings)

public virtual Task<RunQueryResponse> RunQueryAsync(RunQueryRequest request, CallSettings callSettings = null)

Queries for entities.

Parameters
NameDescription
requestRunQueryRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskRunQueryResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
RunQueryRequest request = new RunQueryRequest
{
    ReadOptions = new ReadOptions(),
    PartitionId = new PartitionId(),
    Query = new Query(),
    ProjectId = "",
    DatabaseId = "",
    ExplainOptions = new ExplainOptions(),
};
// Make the request
RunQueryResponse response = await datastoreClient.RunQueryAsync(request);

RunQueryAsync(RunQueryRequest, CancellationToken)

public virtual Task<RunQueryResponse> RunQueryAsync(RunQueryRequest request, CancellationToken cancellationToken)

Queries for entities.

Parameters
NameDescription
requestRunQueryRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskRunQueryResponse

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
RunQueryRequest request = new RunQueryRequest
{
    ReadOptions = new ReadOptions(),
    PartitionId = new PartitionId(),
    Query = new Query(),
    ProjectId = "",
    DatabaseId = "",
    ExplainOptions = new ExplainOptions(),
};
// Make the request
RunQueryResponse response = await datastoreClient.RunQueryAsync(request);

ShutdownDefaultChannelsAsync()

public static Task ShutdownDefaultChannelsAsync()

Shuts down any channels automatically created by Create() and CreateAsync(CancellationToken). Channels which weren't automatically created are not affected.

Returns
TypeDescription
Task

A task representing the asynchronous shutdown operation.

Remarks

After calling this method, further calls to Create() and CreateAsync(CancellationToken) will create new channels, which could in turn be shut down by another call to this method.