---
title: "Entity definitions client"
slug: "entity-definitions-client-1523390"
abstract: "Overview of the Entity definitions client used to perform CRUD operations on entity definitions, with examples."
---
# Entity definitions client

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

> [!warning]
> 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.

> [!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 entity definitions

Entity definitions can be retrieved by name or ID:

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

```

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

```

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

> [!note]
> 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 reference](https://doc.sitecore.com/ch/en/developers/cloud-dev/overview.html "Overview") 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:

```shell
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
});

definition.MemberGroups.Add(defaultGroup);

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

```

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

> [!note]
> 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.

```shell
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:

```shell
await MClient.EntityDefinitions.DeleteAsync(definitionId);

```

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

```