ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.Data.DDL Namespace / SchemaBuilder Class / Build Method
Example Version

Build Method (SchemaBuilder)
Performs all enqueued operations. This method must be called on the MCT. Use QueuedTask.Run.
Syntax
public bool Build()

Return Value

true if all operations ran successfully; otherwise false. Any returned errors and error messages can be accessed in ErrorMessages
Exceptions
ExceptionDescription
There are no enqueued operations to run.
A geodatabase-related exception has occurred.
This operation cannot be invoked inside Geodatabase.ApplyEdits() or when editing is in progress.
This operation cannot be invoked when editing is in progress.
This method or property must be called within the lambda passed to QueuedTask.Run.
Remarks
If an edit session is in progress on the specified geodatabase or knowledge graph an InvalidOperationException will be thrown.
If executing schema operations on a knowledge graph from within an addin, to ensure proper refresh of the application UI, schema builder operations should be executed within a call to knowledgeGraph.ApplySchemaEdits(sb) where the knowledge graph is the same knowledge graph used initialize the schema builder via its constructor. Calling schemaBuilder.Build() directly when it has been constructed with a knowledge graph may result in the application UI not refreshing correctly. Additionally, calling knowledgeGraph.ApplySchemaEdits(sb) when the schema builder was initialized with a geodatabase (not a knowledge graph) will result in an InvalidOperationException.

Currently, the following operations are supported for knowledge graphs:
 o Create (named object types and attribute index)
 o Delete named object types
 o Modify*

*Refer to Modify(KnowledgeGraphTypeDescription) for specific details on what modifications can be made to knowledge graph named object type schemas.
Example
Creating a Table
public void CreateTableSnippet(Geodatabase geodatabase, CodedValueDomain inspectionResultsDomain)
{
    // Create a PoleInspection table with the following fields
    //  GlobalID
    //  ObjectID
    //  InspectionDate (date)
    //  InspectionResults (pre-existing InspectionResults coded value domain)
    //  InspectionNotes (string)

    // This static helper routine creates a FieldDescription for a GlobalID field with default values
    FieldDescription globalIDFieldDescription = FieldDescription.CreateGlobalIDField();

    // This static helper routine creates a FieldDescription for an ObjectID field with default values
    FieldDescription objectIDFieldDescription = FieldDescription.CreateObjectIDField();

    // Create a FieldDescription for the InspectionDate field
    FieldDescription inspectionDateFieldDescription = new FieldDescription("InspectionDate", FieldType.Date)
    {
        AliasName = "Inspection Date"
    };

    // This static helper routine creates a FieldDescription for a Domain field (from a pre-existing domain)
    FieldDescription inspectionResultsFieldDescription = FieldDescription.CreateDomainField("InspectionResults", new CodedValueDomainDescription(inspectionResultsDomain));
    inspectionResultsFieldDescription.AliasName = "Inspection Results";

    // This static helper routine creates a FieldDescription for a string field
    FieldDescription inspectionNotesFieldDescription = FieldDescription.CreateStringField("InspectionNotes", 512);
    inspectionNotesFieldDescription.AliasName = "Inspection Notes";

    // Assemble a list of all of our field descriptions
    List<FieldDescription> fieldDescriptions = new List<FieldDescription>()
{ globalIDFieldDescription, objectIDFieldDescription, inspectionDateFieldDescription, inspectionResultsFieldDescription, inspectionNotesFieldDescription };

    // Create a TableDescription object to describe the table to create
    TableDescription tableDescription = new TableDescription("PoleInspection", fieldDescriptions);

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

    // Add the creation of PoleInspection to our list of DDL tasks
    schemaBuilder.Create(tableDescription);

    // Execute the DDL
    bool success = schemaBuilder.Build();

    // Inspect error messages
    if (!success)
    {
        IReadOnlyList<string> errorMessages = schemaBuilder.ErrorMessages;
        //etc.
    }
}
Creating a feature class
public void CreateFeatureClassSnippet(Geodatabase geodatabase, FeatureClass existingFeatureClass, SpatialReference spatialReference)
{
    // Create a Cities feature class with the following fields
    //  GlobalID
    //  ObjectID
    //  Name (string)
    //  Population (integer)

    // This static helper routine creates a FieldDescription for a GlobalID field with default values
    FieldDescription globalIDFieldDescription = FieldDescription.CreateGlobalIDField();

    // This static helper routine creates a FieldDescription for an ObjectID field with default values
    FieldDescription objectIDFieldDescription = FieldDescription.CreateObjectIDField();

    // This static helper routine creates a FieldDescription for a string field
    FieldDescription nameFieldDescription = FieldDescription.CreateStringField("Name", 255);

    // This static helper routine creates a FieldDescription for an integer field
    FieldDescription populationFieldDescription = FieldDescription.CreateIntegerField("Population");

    // Assemble a list of all of our field descriptions
    List<FieldDescription> fieldDescriptions = new List<FieldDescription>()
{ globalIDFieldDescription, objectIDFieldDescription, nameFieldDescription, populationFieldDescription };

    // Create a ShapeDescription object
    ShapeDescription shapeDescription = new ShapeDescription(GeometryType.Point, spatialReference);

    // Alternatively, ShapeDescriptions can be created from another feature class.  In this case, the new feature class will inherit the same shape properties of the existing class
    ShapeDescription alternativeShapeDescription = new ShapeDescription(existingFeatureClass.GetDefinition());

    // Create a FeatureClassDescription object to describe the feature class to create
    FeatureClassDescription featureClassDescription =
      new FeatureClassDescription("Cities", fieldDescriptions, shapeDescription);

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

    // Add the creation of the Cities feature class to our list of DDL tasks
    schemaBuilder.Create(featureClassDescription);

    // Execute the DDL
    bool success = schemaBuilder.Build();

    // Inspect error messages
    if (!success)
    {
        IReadOnlyList<string> errorMessages = schemaBuilder.ErrorMessages;
        //etc.
    }
}
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();
}
Creating a Range domain
public void CreateRangeDomainSnippet(Geodatabase geodatabase)
{
    // Create a range description with minimum value = 0 and maximum value = 1000
    RangeDomainDescription rangeDomainDescriptionMinMax = new RangeDomainDescription("RangeDomain_0_1000",
      FieldType.Integer, 0, 1000)
    { Description = "Domain value ranges from 0 to 1000" };

    SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);

    // Create  a range domain 
    schemaBuilder.Create(rangeDomainDescriptionMinMax);
    schemaBuilder.Build();
}
Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3 or higher.
See Also