Google Cloud Datastore v1 API - Class DatastoreClient (4.12.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
Type Description
string

DefaultScopes

public static IReadOnlyList<string> DefaultScopes { get; }

The default Datastore scopes.

Property Value
Type Description
IReadOnlyListstring
Remarks

GrpcClient

public virtual Datastore.DatastoreClient GrpcClient { get; }

The underlying gRPC Datastore client

Property Value
Type Description
DatastoreDatastoreClient

ServiceMetadata

public static ServiceMetadata ServiceMetadata { get; }

The service metadata associated with this client type.

Property Value
Type Description
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
Name Description
request AllocateIdsRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
projectId string

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

keys IEnumerableKey

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request AllocateIdsRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request AllocateIdsRequest

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Name Description
projectId string

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

keys IEnumerableKey

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
projectId string

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

keys IEnumerableKey

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Name Description
request BeginTransactionRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
projectId string

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request BeginTransactionRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request BeginTransactionRequest

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Name Description
projectId string

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
projectId string

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Name Description
request CommitRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
projectId string

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

mode CommitRequestTypesMode

The type of commit to perform. Defaults to TRANSACTIONAL.

transaction ByteString

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].

mutations IEnumerableMutation

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.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
projectId string

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

mode CommitRequestTypesMode

The type of commit to perform. Defaults to TRANSACTIONAL.

mutations IEnumerableMutation

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.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request CommitRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request CommitRequest

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Name Description
projectId string

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

mode CommitRequestTypesMode

The type of commit to perform. Defaults to TRANSACTIONAL.

transaction ByteString

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].

mutations IEnumerableMutation

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.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
projectId string

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

mode CommitRequestTypesMode

The type of commit to perform. Defaults to TRANSACTIONAL.

transaction ByteString

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].

mutations IEnumerableMutation

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.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Name Description
projectId string

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

mode CommitRequestTypesMode

The type of commit to perform. Defaults to TRANSACTIONAL.

mutations IEnumerableMutation

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.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
projectId string

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

mode CommitRequestTypesMode

The type of commit to perform. Defaults to TRANSACTIONAL.

mutations IEnumerableMutation

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.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Type Description
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
Name Description
cancellationToken CancellationToken

The CancellationToken to use while creating the client.

Returns
Type Description
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
Name Description
request LookupRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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(), },
    PropertyMask = new PropertyMask(),
    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
Name Description
projectId string

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

readOptions ReadOptions

The options for this lookup request.

keys IEnumerableKey

Required. Keys of entities to look up.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request LookupRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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(), },
    PropertyMask = new PropertyMask(),
    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
Name Description
request LookupRequest

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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(), },
    PropertyMask = new PropertyMask(),
    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
Name Description
projectId string

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

readOptions ReadOptions

The options for this lookup request.

keys IEnumerableKey

Required. Keys of entities to look up.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
projectId string

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

readOptions ReadOptions

The options for this lookup request.

keys IEnumerableKey

Required. Keys of entities to look up.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Name Description
request ReserveIdsRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
projectId string

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

keys IEnumerableKey

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request ReserveIdsRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request ReserveIdsRequest

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Name Description
projectId string

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

keys IEnumerableKey

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
projectId string

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

keys IEnumerableKey

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Name Description
request RollbackRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
projectId string

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

transaction ByteString

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request RollbackRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request RollbackRequest

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Name Description
projectId string

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

transaction ByteString

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
projectId string

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

transaction ByteString

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Name Description
request RunAggregationQueryRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request RunAggregationQueryRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request RunAggregationQueryRequest

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Name Description
request RunQueryRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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
Name Description
request RunQueryRequest

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

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
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 = "",
    PropertyMask = new PropertyMask(),
    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
Name Description
request RunQueryRequest

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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 = "",
    PropertyMask = new PropertyMask(),
    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
Type Description
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.