logo
logo

Entities client

The SDK provides an Entities client to perform CRUD operations on entities.

Note

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

Get entities

The following method gets an entity by id:

IEntity entity = await MClient.Entities.GetAsync(entityId);

When the entity does not exist or the user does not have enough permissions to read it, the method returns null.

Note

There are many options to load entities by id, by identifier or by definition. For more information about the different options, please refer to the IEntitiesClient in the API reference documentation.

Note

It is possible to pass loading configurations when loading entities. For more information about loading configurations, please refer to the load configurations section.

Create entities

An entity can only be instantiated using the EntityFactory.

In the following snippet, an Asset entity is created (locally).

IEntity asset = await MClient.EntityFactory.CreateAsync("M.Asset");
asset.SetPropertyValue("Title", "AssetName");

In the following snippet, the locally created Asset entity is sent to the server to be validated and persisted.

long id = await MClient.Entities.SaveAsync(asset);

The returned id is the id of the newly created entity. To get the latest version of this entity, use the id to get it from the server again.

Update entities

Similar to creating entities, use the save method on the entities client after performing the modification.

long id = await MClient.Entities.SaveAsync(asset);

The returned id is the same id of the entity. To get the latest version of this entity, use the id to get it from the server again.

Delete entities

Entity deletion can be achieved by using the 'Delete' method of the entities client. The entity id needs to be specified for deletion.

await MClient.Entities.DeleteAsync(entityId);

Can we improve this article ? Provide feedback