public sealed 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.
Namespace
Google.Cloud.Datastore.V1Assembly
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. |
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. |
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. |
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(Int64)
public Key CreateKey(long id)
Creates a key for the given entity ID.
Parameter | |
---|---|
Name | Description |
id | Int64 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. |