ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.Data.DDL Namespace / SchemaBuilder Class / Delete Method
Indicates the object to be deleted.
Example Version

Delete Method (SchemaBuilder)
Enqueue the delete operation on the object with the name referred to by the Description. This method must be called on the MCT. Use QueuedTask.Run.
Syntax
public void Delete( 
   Description description
)

Parameters

description
Indicates the object to be deleted.
Exceptions
ExceptionDescription
description is null.
The FID index cannot be deleted
This method or property must be called within the lambda passed to QueuedTask.Run.
Remarks
When deleting domains, a CodedValueDomainDescription must be used to delete a ArcGIS.Core.Data.CodedValueDomain and a RangeDomainDescription must be used to delete a ArcGIS.Core.Data.RangeDomain. When deleting an object from a geodatabase, the geodatabase must be set as the datasource. When deleting a named object type from a knowledge graph, the knowledge graph must be set as the datasource. If the wrong datasource is detected for the given input description then a System.InvalidOperationException will be thrown.
An attribute index on object id cannot be deleted. Attempting to delete the attribute index on the global id field of a knowledge graph dataset will be ignored.
Example
Deleting a Table
public void DeleteTableSnippet(Geodatabase geodatabase, Table table)
{
    // Create a TableDescription object
    TableDescription tableDescription = new TableDescription(table.GetDefinition());

    // Create a SchemaBuilder object
    SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);

    // Add the deletion of the table to our list of DDL tasks
    schemaBuilder.Delete(tableDescription);

    // Execute the DDL
    bool success = schemaBuilder.Build();
}
Deleting a Feature Class
public void DeleteFeatureClassSnippet(Geodatabase geodatabase, FeatureClass featureClass)
{
    // Create a FeatureClassDescription object
    FeatureClassDescription featureClassDescription = new FeatureClassDescription(featureClass.GetDefinition());

    // Create a SchemaBuilder object
    SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);

    // Add the deletion fo the feature class to our list of DDL tasks
    schemaBuilder.Delete(featureClassDescription);

    // Execute the DDL
    bool success = schemaBuilder.Build();
}
Deleting a FeatureDataset
public void DeleteFeatureDatasetSnippet(Geodatabase geodatabase)
{
    // Deleting a FeatureDataset named as 'Parcel_Information'

    FeatureDatasetDefinition featureDatasetDefinition = geodatabase.GetDefinition<FeatureDatasetDefinition>("Parcel_Information");
    FeatureDatasetDescription featureDatasetDescription =
      new FeatureDatasetDescription(featureDatasetDefinition);

    SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);

    // Delete an existing feature dataset named as 'Parcel_Information'
    schemaBuilder.Delete(featureDatasetDescription);
    schemaBuilder.Build();
}
Removing attribute index
public void RemoveAttributeIndex(SchemaBuilder schemaBuilder, FeatureClassDefinition featureClassDefinition, string attributeIndexName)
{
    // Find a index to be removed 
    ArcGIS.Core.Data.Index indexToRemove = featureClassDefinition.GetIndexes().First(f => f.GetName().Equals(attributeIndexName));

    // Index description of the index to be removed 
    AttributeIndexDescription indexDescriptionToRemove = new AttributeIndexDescription(indexToRemove, new TableDescription(featureClassDefinition));

    // Enqueue the DDL operation to remove index 
    schemaBuilder.Delete(indexDescriptionToRemove);

    // Execute the delete index operation
    bool isDeleteIndexSuccess = schemaBuilder.Build();
}
Removing spatial index
public void RemoveSpatialIndex(SchemaBuilder schemaBuilder, FeatureClassDefinition featureClassDefinition)
{
    // Create a spatial description  
    SpatialIndexDescription spatialIndexDescription = new SpatialIndexDescription(new FeatureClassDescription(featureClassDefinition));

    // Enqueue the DDL operation to remove index 
    schemaBuilder.Delete(spatialIndexDescription);

    // Execute the delete index operation
    bool isDeleteIndexSuccess = schemaBuilder.Build();
}
Delete domain
public void DeleteDomain(Geodatabase geodatabase, string domainNameToBeDeleted = "PipeMaterial")
{
    SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
    CodedValueDomain codedValueDomain = geodatabase.GetDomains().First(f => f.GetName().Equals(domainNameToBeDeleted)) as CodedValueDomain;
    CodedValueDomainDescription codedValueDomainDescription = new CodedValueDomainDescription(codedValueDomain);

    // Deleting a coded value domain
    schemaBuilder.Delete(codedValueDomainDescription);
    schemaBuilder.Build();
}
Deleting a relationship class
public void DeleteRelationshipClass(SchemaBuilder schemaBuilder, RelationshipClassDefinition relationshipClassDefinition)
{
    schemaBuilder.Delete(new RelationshipClassDescription(relationshipClassDefinition));
    schemaBuilder.Build();
}
Delete Entity and Relationship Types with SchemaBuilder
await QueuedTask.Run(() =>
{
  using (var kg = GetKnowledgeGraph())
  {
    if (kg == null)
      return;

    var entity_name = "PhoneCall";
    var relate_name = "WhoCalledWho";

    var entityDesc = new KnowledgeGraphEntityTypeDescription(entity_name);
    var relateDesc = new KnowledgeGraphRelationshipTypeDescription(relate_name);

    //Run the schema builder
    try
    {
      SchemaBuilder sb = new(kg);
      sb.Delete(entityDesc);
      sb.Delete(relateDesc);
      //Use the KnowledgeGraph extension method 'ApplySchemaEdits(...)'
      //to refresh the Pro UI
      if (!kg.ApplySchemaEdits(sb))
      {
        var err_msg = string.Join(",", sb.ErrorMessages.ToArray());
        System.Diagnostics.Debug.WriteLine($"Entity/Relate Delete error: {err_msg}");
      }
    }
    catch (Exception ex)
    {
      System.Diagnostics.Debug.WriteLine(ex.ToString());
    }
  }
});
Delete Attribute Indexes on KG Schemas with SchemaBuilder
await QueuedTask.Run(() =>
{
  using (var kg = GetKnowledgeGraph())
  {
    if (kg == null)
      return;

    var entity_name = "PhoneCall";

    //indexes are managed on the GDB objects...
    var entity_table_def = kg.GetDefinition<TableDefinition>(entity_name);
    var entity_table_desc = new TableDescription(entity_table_def);

    var indexes = entity_table_def.GetIndexes();
    foreach (var idx in indexes)
    {
      System.Diagnostics.Debug.WriteLine($"Index {idx.GetName()}");
    }
    var idx1 = indexes.FirstOrDefault(
      idx => idx.GetName().ToLower() == "Index1".ToLower());
    var idx2 = indexes.FirstOrDefault(
      idx => idx.GetName().ToLower() == "Index2".ToLower());

    if (idx1 == null && idx2 == null)
      return;

    //Run the schema builder
    try
    {
      SchemaBuilder sb = new(kg);

      if (idx1 != null)
      {
        var idx_attr = new AttributeIndexDescription(idx1, entity_table_desc);
        sb.Delete(idx_attr);
      }
      if (idx2 != null)
      {
        var idx_attr = new AttributeIndexDescription(idx2, entity_table_desc);
        sb.Delete(idx_attr);
      }

      if (!kg.ApplySchemaEdits(sb))
      {
        var err_msg = string.Join(",", sb.ErrorMessages.ToArray());
        System.Diagnostics.Debug.WriteLine($"Delete index error: {err_msg}");
      }
    }
    catch (Exception ex)
    {
      System.Diagnostics.Debug.WriteLine(ex.ToString());
    }
  }
});
Delete Domain on KG Schemas with SchemaBuilder
await QueuedTask.Run(() =>
{
  using (var kg = GetKnowledgeGraph())
  {
    if (kg == null)
      return;

    //Get all the domains in the KG
    var domains = kg.GetDomains();
    var sb = new SchemaBuilder(kg);

    foreach (var domain in domains)
    {
      //skip the special provenance domain
      var name = domain.GetName();
      if (string.Compare(name, "esri__provenanceSourceType", true) == 0)
        continue;//skip this one

      //Delete all other domains
      if (domain is RangeDomain rd)
        sb.Delete(new RangeDomainDescription(rd));
      else if (domain is CodedValueDomain cvd)
        sb.Delete(new CodedValueDomainDescription(cvd));
    }

    try
    {
      //note: will throw an InvalidOperationException if there are no operations
      //to run. Will also delete associated fields dependent on deleted domain(s)
      if (!kg.ApplySchemaEdits(sb))
      {
        var err_msg = string.Join(",", sb.ErrorMessages.ToArray());
        System.Diagnostics.Debug.WriteLine($"Delete domains error: {err_msg}");
      }
    }
    catch (Exception ex)
    {
      System.Diagnostics.Debug.WriteLine(ex.ToString());
    }
  }
});
Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3 or higher.
See Also