Entity factory

The entity factory creates entity instances from a specific entity definition.

Entities are complex objects and their members can change at runtime by modifying the entity definition. It is therefore required to create instances using a factory. The factory resolves the entity definition and configures the entity instance with the correct members and configuration. A new instance always contains all members.

Note

The client variable in the following code examples refers to the ContentHubClient instance. When using the JavaScript SDK, the variable name can be chosen freely, but is also called client at instantiation in the documentation.

Creating entities

Creating entities can be done using the createAsync method, which returns a new entity instance. It is very important to create the entity with the correct cultures (an optional argument), because this cannot be changed without reloading the entity.

For example, creating a new asset entity in the default culture can be done like this:

RequestResponse
var asset: IEntity = await client.entityFactory.createAsync("M.Asset");

The entity can be created by passing the entity definition name or the entity definition instance.

Note

The entity instance is not persisted. The factory only creates an object. If the entity needs to be persisted, use the saveAsync on the IEntitiesClient.

Do you have some feedback for us?

If you have suggestions for improving this article,