---
title: "Entity definitions client"
slug: "entity-definitions-client"
abstract: "Use the Entity definitions client to get, create, update, or delete entity definitions."
---
# Entity definitions client

The Entity definitions client can be used to perform CRUD operations on entity definitions.

> [!warning]
> Use extreme caution. Adding, removing, or deleting entity definitions can have serious consequences.

## Get entity definitions { .notintoc }

Entity definitions can be retrieved by name or `id`:

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

```

```csharp
IEntityDefinition assetDefinition = await MClient.EntityDefinitions.GetAsync(<ASSET_DEFINITION_ID>);

```

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

> [!note]
> There are many more overloads for retrieving entity definitions. It's also possible to resolve names to IDs and vice versa. See the [API docs](https://doc.sitecore.com/ch/en/developers/api-reference/index-en.html) for a complete overview.

## Create entity definitions { .notintoc }

The SDK lets you create entity definition objects directly, without a factory. A very simple entity definition can be created as follows:

```csharp
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(<DEFAULT_GROUP>);

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 { .notintoc }

Use the save method on the entity definitions client after making a change.

```csharp
long id = await MClient.EntityDefinitions.SaveAsync(<DEFINITION>);

```

This returns the ID of the updated entity definition.

## Delete entity definitions { .notintoc }

Entity definitions can be deleted by name or by `id`:

```csharp
await MClient.EntityDefinitions.DeleteAsync(<DEFINITION_ID>);

```

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

```