// ** Create Entity request **
// Desc: Creates an entity in the current Organization
CreateEntityRequest cent = new CreateEntityRequest();
// Entity Metadata
cent.Entity = new Microsoft.Xrm.Sdk.Metadata.EntityMetadata(){
SchemaName = "_customEntity",
DisplayName = new Label("_custom",1033),
DisplayCollectionName = new Label("_customentities",1033),
Description = new Label("created using Entity request",1033),
OwnershipType = OwnershipTypes.OrganizationOwned,
IsActivity=false
};
// Attribute metadata
cent.PrimaryAttribute = new StringAttributeMetadata()
{
SchemaName = "new_accountname",
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
MaxLength = 100,
Format = StringFormat.Text,
DisplayName = new Label("Account Name", 1033),
Description = new Label("The primary attribute for the Bank Account entity.", 1033)
};
// Executes the request(Org service)
_service.Execute(cent);