Entities client
The Entities client can be used to perform CRUD operations on entities.
Get entities
The following method gets an entity by ID:
IEntity entity = await MClient.Entities.GetAsync(<ENTITY_ID>);
If the entity doesn't exist or the user doesn't have permission to read it, the method returns null.
There are many options to load entities by ID, by identifier, or by definition. For more information about loading configurations, please refer to the load configurations section.
Create entities
You can only create an entity with the CreateAsync method.
In the following code snippet, an Asset entity is created locally.
IEntity asset = await MClient.EntityFactory.CreateAsync("M.Asset");
In the following code 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. You can use this ID to get the latest version of the entity from the server.
Update entities
Use the SaveAsync method on the entities client after making a change.
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
You can delete an entity with the DeleteAsync method and the entity ID.
await MClient.Entities.DeleteAsync(<ENTITY_ID>);