Google Cloud Datastore v1 API - Class KeyFactory (4.10.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
Name Description
parent Entity

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

kind string

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
Name Description
parent Key

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

kind string

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
Name Description
partitionId PartitionId

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

kind string

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

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

namespaceId string

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

kind string

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

KeyFactory(string, string, string, string)

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

Creates a key factory for the root of a partition.

Parameters
Name Description
projectId string

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

namespaceId string

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

databaseId string

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

kind string

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
Type Description
Key

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

CreateKey(long)

public Key CreateKey(long id)

Creates a key for the given entity ID.

Parameter
Name Description
id long

The numeric entity ID.

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

The entity name. Must not be null.

Returns
Type Description
Key

A key whose final path element contains the given name.