Google Cloud Datastore v1 API - Class KeyFactory (4.4.0)

public sealed class KeyFactory

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

Provides a convenient way of producing keys of a specific kind, from a specified parent entity or key, or for root entities based on a partition ID.

Inheritance

Object > KeyFactory

Namespace

Google.Cloud.Datastore.V1

Assembly

Google.Cloud.Datastore.V1.dll

Remarks

If the key factory is constructed with just a partition ID and kind, then the parent key has an empty path, and all keys created by the factory will be root keys. Otherwise, all keys created by the factory will be direct children of the parent key, so both the parent key itself and any ancestors of that key will be ancestors of the child key. Ancestors can be determined in queries using HasAncestor(Key).

Constructors

KeyFactory(Entity, String)

public KeyFactory(Entity parent, string kind)

Creates a key factory for children of the given key. Keys created by the new factory will have the same path as this key, but with one extra path element.

Parameters
NameDescription
parentEntity

The "parent" entity for keys created by the new factory. Must not be null, and must have a key.

kindString

The kind of child entity keys to create. Must not be null.

Remarks

The entity key is cloned before being stored, so may be mutated after the factory is constructed without affecting the factory.

KeyFactory(Key, String)

public KeyFactory(Key parent, string kind)

Creates a key factory for children of the given key. Keys created by the new factory will have the same path as this key, but with one extra path element.

Parameters
NameDescription
parentKey

The "parent" key for keys created by the new factory. Must not be null.

kindString

The kind of child entity keys to create. Must not be null.

Remarks

The key is cloned before being stored, so may be mutated after the factory is constructed without affecting the factory.

KeyFactory(PartitionId, String)

public KeyFactory(PartitionId partitionId, string kind)

Creates a key factory for the root of a partition.

Parameters
NameDescription
partitionIdPartitionId

The partition ID for the factory. Must not be null.

kindString

The kind of root entity keys to create. Must not be null.

KeyFactory(String, String, String)

public KeyFactory(string projectId, string namespaceId, string kind)

Creates a key factory for the root of a partition.

Parameters
NameDescription
projectIdString

The project ID for the factory. Must not be null.

namespaceIdString

The namespace ID for the factory. May be null in which case an empty string is used.

kindString

The kind of root entity keys to create. Must not be null.

Methods

CreateIncompleteKey()

public Key CreateIncompleteKey()

Creates a key with only the kind specified in the final path element, intended for insertions where the ID is populated by the server.

Returns
TypeDescription
Key

A key with no name or ID in the final path element.

CreateKey(Int64)

public Key CreateKey(long id)

Creates a key for the given entity ID.

Parameter
NameDescription
idInt64

The numeric entity ID.

Returns
TypeDescription
Key

A key whose final path element contains the given ID.

CreateKey(String)

public Key CreateKey(string name)

Creates a key for the given entity name.

Parameter
NameDescription
nameString

The entity name. Must not be null.

Returns
TypeDescription
Key

A key whose final path element contains the given name.