Entity definitions client

The SDK provides an entity definitions client to perform CRUD operations on entity definitions.


Adding, removing or deleting entity definitions can have very large consequences and should be done with extreme caution. With great power comes great responsibility. When in doubt, ask before doing anything.

Get entity definitions

Entity definitions can be retrieved by name or ID:


IEntityDefinition assetDefinition = await MClient.EntityDefinitions.GetAsync("M.Asset");


IEntityDefinition assetDefinition = await MClient.EntityDefinitions.GetAsync(assetDefId);

When the entity definition does not exist, the method returns null.


There are many more overloads for getting one or more entity definitions. It is also possible to resolve names to ids and vice versa. See the API docs for a complete overview.

Create entity definitions

Entity definition objects can be directly instantiated and do not need a factory. A very simple entity definition can be created like this:


IEntityDefinition definition = new EntityDefinition
  Name = "M.Demo.Definition",
  DisplayTemplate = "{M.Demo.Definition.Name}"

var defaultGroup = new MemberGroup { Name = "Default" };
defaultGroup.MemberDefinitions.Add(new StringPropertyDefinition
  Name = "M.Demo.Definition.Name",
  IsUnique = true


long id = await MClient.EntityDefinitions.SaveAsync(definition);

The returned ID is the ID of the newly created entity definition.


The EntityDefinition can be imported from Stylelabs.M.Sdk.Models.Base, and the property member definitions from Stylelabs.M.Sdk.Models.Base.PropertyDefinitions.

Update entity definitions

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


long id = await MClient.EntityDefinitions.SaveAsync(definition);

The returned ID is the same ID of the entity definition.

Delete entity definitions

Entity definitions can be deleted by name or by ID:


await MClient.EntityDefinitions.DeleteAsync(definitionId);


await MClient.EntityDefinitions.DeleteAsync("M.Demo.Definition");

Do you have some feedback for us?

If you have suggestions for improving this article,