ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.Data.DDL Namespace / SchemaBuilder Class / SchemaBuilder Constructor / SchemaBuilder Constructor(KnowledgeGraph)
The ArcGIS.Core.Data.Knowledge.KnowledgeGraph where the schema operations will take place.
Example Version

SchemaBuilder Constructor(KnowledgeGraph)
Creates a schema builder object based on the input ArcGIS.Core.Data.Knowledge.KnowledgeGraph. This method must be called on the MCT. Use QueuedTask.Run.
Syntax
public SchemaBuilder( 
   KnowledgeGraph knowledgeGraph
)

Parameters

knowledgeGraph
The ArcGIS.Core.Data.Knowledge.KnowledgeGraph where the schema operations will take place.
Exceptions
ExceptionDescription
knowledgeGraph is null.
This method or property must be called within the lambda passed to QueuedTask.Run.
Example
Create 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";

    //Entity Fields
    var descs1 =
        new List<KnowledgeGraphPropertyDescription>();
    descs1.Add(
      new KnowledgeGraphPropertyDescription("PhoneOwner", FieldType.String));
    descs1.Add(
      new KnowledgeGraphPropertyDescription("PhoneNumber", FieldType.String));
    descs1.Add(
      new KnowledgeGraphPropertyDescription("LocationID", FieldType.BigInteger));
    descs1.Add(
      new KnowledgeGraphPropertyDescription("DateAndTime", FieldType.Date));

    //Relate Fields
    var descs2 =
        new List<KnowledgeGraphPropertyDescription>();
    descs2.Add(
      new KnowledgeGraphPropertyDescription("Foo", FieldType.String));
    descs2.Add(
      new KnowledgeGraphPropertyDescription("Bar", FieldType.String));


    var includeShape = true;//change to false to omit the shape column
    var hasZ = false;
    var hasM = false;

    KnowledgeGraphEntityTypeDescription entityDesc = null;
    KnowledgeGraphRelationshipTypeDescription relateDesc = null;
    if (includeShape)
    {
      var sr = kg.GetSpatialReference();
      var shp_desc = new ShapeDescription(GeometryType.Point, sr)
      {
        HasM = hasM,
        HasZ = hasZ
      };
      entityDesc = new KnowledgeGraphEntityTypeDescription(
        entity_name, descs1, shp_desc);
      relateDesc = new KnowledgeGraphRelationshipTypeDescription(
        relate_name, descs2, shp_desc);
    }
    else
    {
      entityDesc = new KnowledgeGraphEntityTypeDescription(
        entity_name, descs1);
      relateDesc = new KnowledgeGraphRelationshipTypeDescription(
        relate_name, descs2);
    }
    //Run the schema builder
    try
    {
      SchemaBuilder sb = new(kg);
      sb.Create(entityDesc);
      sb.Create(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 Create error: {err_msg}");
      }
    }
    catch (Exception ex)
    {
      System.Diagnostics.Debug.WriteLine(ex.ToString());
    }
  }
});
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());
    }
  }
});
Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3.4 or higher.
See Also