Skip to content

breeze-client / EntityKey

Class: EntityKey ​

Defined in: src/entity/entity-key.ts:12

An EntityKey is an object that represents the unique identity of an entity. EntityKey's are immutable.

Constructors ​

Constructor ​

new EntityKey(entityType, keyValues): EntityKey

Defined in: src/entity/entity-key.ts:59

Constructs a new EntityKey. Each entity within an EntityManager will have a unique EntityKey.

ts
// assume Employee is registered with the MetadataStore
const entityKey = new EntityKey(Employee, 1);

EntityKey's may also be found by calling EntityAspect.getKey()

ts
// assume employee1 is an existing Employee entity
const empKey = employee1.entityAspect.getKey();

A key of more than one property is clearest given by name, in any order:

ts
const detailKey = new EntityKey(OrderDetail, { orderID: 10248, productID: 11 });

or as an array, in the order of the type's EntityType.keyProperties: the order of the key's definition on the server - HasKey(od => new { od.OrderID, od.ProductID }) - which a generated entity class states in its doc comment, as Key: orderID, productID.

ts
const sameKey = new EntityKey(OrderDetail, [10248, 11]);

A wrong order is not an error - it is a valid key for another row - which is why the named form is better for these.

Parameters ​

entityType ​

EntityType | (() => Entity)

The EntityType of the entity, or a class registered for it with MetadataStore.registerEntityTypeCtor.

keyValues ​

any

The key's value; for a key of more than one property, an object of values by property name, or an array in key order. A named value that is not part of the key, or a key property with no value, throws.

Returns ​

EntityKey

Properties ​

entityType ​

entityType: EntityType

Defined in: src/entity/entity-key.ts:18

The 'EntityType' that this is a key for. Read Only


values ​

values: any[]

Defined in: src/entity/entity-key.ts:21

An array of the values for this key. This will usually only have a single element, unless the entity type has a multipart key. Read Only

Methods ​

equals() ​

equals(entityKey): boolean

Defined in: src/entity/entity-key.ts:132

Used to compare EntityKeys are determine if they refer to the same Entity. There is also an static version of 'equals' with the same functionality.

ts
// assume Employee is registered with the MetadataStore
const empKey1 = new EntityKey(Employee, 1);
// assume employee1 is an existing Employee entity
const empKey2 = employee1.entityAspect.getKey();
if (empKey1.equals(empKey2)) {
    // do something  ...
}

Parameters ​

entityKey ​

EntityKey

Returns ​

boolean


toJSON() ​

toJSON(): object

Defined in: src/entity/entity-key.ts:102

Returns the plain form of this key - { entityType, values }, with the entity type's qualified name - which JSON.stringify uses and EntityKey.fromJSON turns back into a key. Breeze uses it to record temporary keys in an EntityManager.exportEntities bundle.

Returns ​

entityType ​

entityType: string

The qualified name of the key's entity type, such as "Customer:#Northwind.Models".

values ​

values: any[]

The key's values, one per key property.


toString() ​

toString(altEntityType?): string

Defined in: src/entity/entity-key.ts:145

Returns this key as a string: the entity type's qualified name, a hyphen, and the key values joined by ::: - such as "Order:#Northwind.Models-10248". Given altEntityType, that type's name is used instead. Breeze uses this form in error messages and as the property names of an ITempKeyMap.

Parameters ​

altEntityType? ​

EntityType

Returns ​

string


createKeyString() ​

static createKeyString(keyValues): string

Defined in: src/entity/entity-key.ts:175

hidden

Parameters ​

keyValues ​

any[]

Returns ​

string


equals() ​

static equals(k1, k2): boolean

Defined in: src/entity/entity-key.ts:162

Used to compare EntityKeys are determine if they refer to the same Entity. There is also an instance version of 'equals' with the same functionality.

ts
// assume Employee is registered with the MetadataStore
const empKey1 = new EntityKey(Employee, 1);
// assume employee1 is an existing Employee entity
const empKey2 = employee1.entityAspect.getKey();
if (EntityKey.equals(empKey1, empKey2)) {
    // do something  ...
}

Parameters ​

k1 ​

EntityKey

k2 ​

EntityKey

Returns ​

boolean


fromJSON() ​

static fromJSON(json, metadataStore): EntityKey

Defined in: src/entity/entity-key.ts:113

Recreates a key from the output of EntityKey.toJSON, looking its entity type up in metadataStore. Throws if the type is not there. Used by EntityManager.importEntities.

Parameters ​

json ​

any

metadataStore ​

MetadataStore

Returns ​

EntityKey

Released under the MIT License.