Class DatastoreClient (3.3.0)

public abstract 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
IReadOnlyList<String>
Remarks

GrpcClient

public virtual Datastore.DatastoreClient GrpcClient { get; }

The underlying gRPC Datastore client

Property Value
TypeDescription
Datastore.DatastoreClient

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 = "",
};
// 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.

keysIEnumerable<Key>

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
Task<AllocateIdsResponse>

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 = "",
};
// 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
Task<AllocateIdsResponse>

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 = "",
};
// 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.

keysIEnumerable<Key>

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
Task<AllocateIdsResponse>

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.

keysIEnumerable<Key>

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
Task<AllocateIdsResponse>

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 = "",
    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
Task<BeginTransactionResponse>

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
BeginTransactionRequest request = new BeginTransactionRequest
{
    ProjectId = "",
    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
Task<BeginTransactionResponse>

A Task containing the RPC response.

Example
// Create client
DatastoreClient datastoreClient = await DatastoreClient.CreateAsync();
// Initialize request argument(s)
BeginTransactionRequest request = new BeginTransactionRequest
{
    ProjectId = "",
    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
Task<BeginTransactionResponse>

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
Task<BeginTransactionResponse>

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 = "",
};
// Make the request
CommitResponse response = datastoreClient.Commit(request);

Commit(String, CommitRequest.Types.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.

modeCommitRequest.Types.Mode

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

mutationsIEnumerable<Mutation>

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, CommitRequest.Types.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.

modeCommitRequest.Types.Mode

The type of commit to perform. Defaults to TRANSACTIONAL.

mutationsIEnumerable<Mutation>

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
Task<CommitResponse>

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 = "",
};
// 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
Task<CommitResponse>

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 = "",
};
// Make the request
CommitResponse response = await datastoreClient.CommitAsync(request);

CommitAsync(String, CommitRequest.Types.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.

modeCommitRequest.Types.Mode

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

mutationsIEnumerable<Mutation>

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
Task<CommitResponse>

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, CommitRequest.Types.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.

modeCommitRequest.Types.Mode

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

mutationsIEnumerable<Mutation>

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
Task<CommitResponse>

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, CommitRequest.Types.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.

modeCommitRequest.Types.Mode

The type of commit to perform. Defaults to TRANSACTIONAL.

mutationsIEnumerable<Mutation>

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
Task<CommitResponse>

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, CommitRequest.Types.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.

modeCommitRequest.Types.Mode

The type of commit to perform. Defaults to TRANSACTIONAL.

mutationsIEnumerable<Mutation>

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
Task<CommitResponse>

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(CancellationToken))

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
Task<DatastoreClient>

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 = "",
};
// 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.

keysIEnumerable<Key>

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
Task<LookupResponse>

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 = "",
};
// 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
Task<LookupResponse>

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 = "",
};
// 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.

keysIEnumerable<Key>

Required. Keys of entities to look up.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task<LookupResponse>

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.

keysIEnumerable<Key>

Required. Keys of entities to look up.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
Task<LookupResponse>

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.

keysIEnumerable<Key>

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
Task<ReserveIdsResponse>

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
Task<ReserveIdsResponse>

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.

keysIEnumerable<Key>

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
Task<ReserveIdsResponse>

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.

keysIEnumerable<Key>

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
Task<ReserveIdsResponse>

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 = "",
};
// 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
Task<RollbackResponse>

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 = "",
};
// 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
Task<RollbackResponse>

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 = "",
};
// 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
Task<RollbackResponse>

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
Task<RollbackResponse>

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);

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
Task<RunQueryResponse>

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 = "",
};
// 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
Task<RunQueryResponse>

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 = "",
};
// 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.