ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data.DDL Namespace / SchemaBuilder Class / Modify Method / Modify(KnowledgeGraphTypeDescription) Method
Indicates the ArcGIS.Core.Data.Knowledge.KnowledgeGraphNamedObjectType to be modified.
Example

In This Topic
    Modify(KnowledgeGraphTypeDescription) Method
    In This Topic
    Enqueue the modify operation on the object referred to by the ArcGIS.Core.Data.DDL.Knowledge.KnowledgeGraphTypeDescription. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    kgTypeDescription
    Indicates the ArcGIS.Core.Data.Knowledge.KnowledgeGraphNamedObjectType to be modified.
    Exceptions
    ExceptionDescription
    kgTypeDescription is null.
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Remarks
    Properties can be added and removed from Entity and Relationship named object types only. Property definitions cannot be changedchanged. Attempting to change an existing property will result in an error (check ErrorMessages for any errors when applying the modify operation). To add new properties, add property descriptions for the new properties to be created to the ArcGIS.Core.Data.DDL.Knowledge.KnowledgeGraphTypeDescription collection of ArcGIS.Core.Data.DDL.Knowledge.KnowledgeGraphTypeDescription.PropertyDescriptions. The following property types can be added:
    Short, Long, Big Integer, Float, Double, Text, Date, Date Only, Time Only, Timestamp Offset, and GUID. To delete existing properties, omit them from (i.e. do not add them to) the collection ofvArcGIS.Core.Data.DDL.Knowledge.KnowledgeGraphTypeDescription.PropertyDescriptions. Note: Object id, global id, shape, origin id (for relationships), and destination id (also for relationships) are never deleted (whether present in the property description or not).
    Example
    Modifying domain
    {
      // Must be called within QueuedTask.Run
      void ModifyDomain(Geodatabase geodatabase, string codedValueDomainName = "Pipe")
      {
        SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
        CodedValueDomain codedValueDomain = geodatabase.GetDomains().First(f => f.GetName().Equals(codedValueDomainName)) as CodedValueDomain;
        CodedValueDomainDescription codedValueDomainDescription = new CodedValueDomainDescription(codedValueDomain);
    
        // Update domain description
        codedValueDomainDescription.Description = "Water Pipe Domain";
    
        // Adding code/value pair
        codedValueDomainDescription.CodedValuePairs.Add("C", "Copper");
    
        schemaBuilder.Modify(codedValueDomainDescription);
    
        // To modify the orders of coded value domain
        // schemaBuilder.Modify(codedValueDomainDescription,SortBy.Name,SortOrder.Ascending);
    
        schemaBuilder.Build();
      }
    }
    Removing subtype field designation
    {
      // Must be called within QueuedTask.Run
      void DeleteSubtypeField(SchemaBuilder schemaBuilder, FeatureClassDefinition featureClassDefinition)
      {
        FeatureClassDescription featureClassDescription = new FeatureClassDescription(featureClassDefinition);
    
        // Set subtype field to null to remove the subtype field designation 
        featureClassDescription.SubtypeFieldDescription = null;
    
        schemaBuilder.Modify(featureClassDescription);
        schemaBuilder.Build();
      }
    }
    Modifying subtypes
    {
      // Must be called within QueuedTask.Run
      void ModifySubtypes(SchemaBuilder schemaBuilder, TableDefinition tableDefinition)
      {
        TableDescription tableDescription = new TableDescription(tableDefinition);
    
        // Remove the first subtype from the table
        IReadOnlyList<Subtype> subtypes = tableDefinition.GetSubtypes();
        tableDescription.SubtypeFieldDescription.Subtypes.Remove(subtypes.First().GetCode());
    
        // Adding a new subtype, 'Utility', in the existing table
        tableDescription.SubtypeFieldDescription.Subtypes.Add(4, "Utility");
    
        // Assigning 'Utility' subtype as the default subtype
        tableDescription.SubtypeFieldDescription.DefaultSubtypeCode = 4;
    
        schemaBuilder.Modify(tableDescription);
        schemaBuilder.Build();
      }
    }
    Add relationship rules to a relationship class
    {
      // Must be called within QueuedTask.Run
      void ModifyRelationshipClass(SchemaBuilder schemaBuilder, AttributedRelationshipClassDefinition attributedRelationshipClassDefinition)
      {
        AttributedRelationshipClassDescription attributedRelationshipClassDescription = new AttributedRelationshipClassDescription(attributedRelationshipClassDefinition);
    
        // Update the relationship split policy
        attributedRelationshipClassDescription.RelationshipSplitPolicy = RelationshipSplitPolicy.UseDefault;
    
        // Add field in the intermediate table
        attributedRelationshipClassDescription.FieldDescriptions.Add(FieldDescription.CreateIntegerField("RelationshipStatus"));
    
        // Add relationship rules based on subtypes,if available
        // Assuming origin class has subtype with code 1
        attributedRelationshipClassDescription.RelationshipRuleDescriptions.Add(
          new RelationshipRuleDescription(1, null));
    
        // Enqueue modify operation
        schemaBuilder.Modify(attributedRelationshipClassDescription);
    
        // Execute modify DDL operation
        schemaBuilder.Build();
      }
    }
    Modifying annotation labels and symbols
    {
      // Must be called within QueuedTask.Run
      void ModifyAnnotationLabelAndSymbols(SchemaBuilder schemaBuilder, AnnotationFeatureClassDefinition annotationFeatureClassDefinition)
      {
        AnnotationFeatureClassDescription annotationFeatureClassDescription = new AnnotationFeatureClassDescription(annotationFeatureClassDefinition);
        IReadOnlyList<CIMLabelClass> labelClasses = annotationFeatureClassDescription.LabelClasses;
    
        // Adding a new annotation label class 
        List<CIMLabelClass> modifiedLabelClasses = new List<CIMLabelClass>(labelClasses);
        modifiedLabelClasses.Add(new CIMLabelClass()
        {
          Name = "RedSymbol",
          TextSymbol = new CIMSymbolReference
          {
            Symbol = new CIMTextSymbol()
            {
              Angle = 45,
              FontType = FontType.Type1,
              FontFamilyName = "Arial",
              FontEffects = FontEffects.Normal,
              HaloSize = 2.0,
    
              Symbol = new CIMPolygonSymbol
              {
                SymbolLayers = new CIMSymbolLayer[]
                  { new CIMSolidFill { Color = CIMColor.CreateRGBColor(255, 0, 0) } },
                UseRealWorldSymbolSizes = true
              }
            },
            MaxScale = 0,
            MinScale = 0,
            SymbolName = "TextSymbol-RED"
          }
        });
    
        // Adding a  new symbol
        annotationFeatureClassDescription.Symbols.Add(new CIMSymbolIdentifier()
        {
          ID = 1001,
          Name = "ID_10001",
          Symbol = new CIMTextSymbol()
          {
            Angle = 43,
            FontEffects = FontEffects.Subscript,
            FontType = FontType.TTOpenType,
            FontStyleName = "Regular",
            FontFamilyName = "Tahoma",
            TextCase = TextCase.Allcaps
          }
        });
    
        // Modify annotation feature class 
        AnnotationFeatureClassDescription modifiedAnnotationFeatureClassDescription = new AnnotationFeatureClassDescription(annotationFeatureClassDescription.Name,
            annotationFeatureClassDescription.FieldDescriptions, annotationFeatureClassDescription.ShapeDescription,
            annotationFeatureClassDescription.GeneralPlacementProperties, modifiedLabelClasses);
    
        // Enqueue modify
        schemaBuilder.Modify(modifiedAnnotationFeatureClassDescription);
    
        // DDL execute
        schemaBuilder.Build();
      }
    }
    Modifying an existing field
    {
      // Must be called within QueuedTask.Run
      void ModifyExistingField(SchemaBuilder schemaBuilder, TableDefinition tableDefinition, string fieldNameToBeModified = "PropertyAddress")
      {
        Field field = tableDefinition.GetFields().FirstOrDefault(f => f.Name.Contains(fieldNameToBeModified));
    
        // Update field's alias name and length
        FieldDescription fieldDescription = new FieldDescription(field)
        {
          AliasName = "Physical Property Address",
          Length = 50
        };
    
        // Update the default value
        fieldDescription.SetDefaultValue("123 Main St");
    
        // Enqueue modify operation
        schemaBuilder.Modify(new TableDescription(tableDefinition), field.Name, fieldDescription);
    
        // Execute DDL
        schemaBuilder.Build();
      }
    }
    Modify Entity and Relationship Type Schemas with SchemaBuilder
    {
      await QueuedTask.Run(() =>
      {
        using (var kg = GetKnowledgeGraph(url))
        {
          var entity_name = "PhoneCall";
          var relate_name = "WhoCalledWho";
    
          var kvp_entity = kg.GetDataModel().GetEntityTypes()
               .First(r => r.Key == entity_name);
          var kvp_relate = kg.GetDataModel().GetRelationshipTypes()
                         .First(r => r.Key == relate_name);
    
          //Let's delete one field and add a new one from each
          //A field gets deleted implicitly if it is not included in the list of
          //fields - or "properties" in this case....so we will remove the last
          //property from the list
          var entity_props = kvp_entity.Value.GetProperties().Reverse().Skip(1).Reverse();
          var prop_descs = new List<KnowledgeGraphPropertyDescription>();
    
          foreach (var prop in entity_props)
          {
            if (prop.FieldType == FieldType.Geometry)
            {
              continue;//skip shape
            }
            var prop_desc = new KnowledgeGraphPropertyDescription(prop);
            prop_descs.Add(prop_desc);
          }
          //deal with shape - we need to keep it
          //SchemaBuilder deletes any field not included in the "modify" list
          ShapeDescription shape_desc = null;
          if (kvp_entity.Value.GetIsSpatial())
          {
            var geom_def = kvp_entity.Value.GetShapeDefinition();
            var shape_name = kvp_entity.Value.GetShapeField();
            shape_desc = new ShapeDescription(
              shape_name, geom_def.geometryType, geom_def.sr);
          }
          //add the new entity property
          prop_descs.Add(
            KnowledgeGraphPropertyDescription.CreateStringProperty("foo", 10));
          //make a description for the entity type - ok if shape_desc is null
          var entityDesc = new KnowledgeGraphEntityTypeDescription(
            entity_name, prop_descs, shape_desc);
    
          //Add the entity type description to the schema builder using 'Modify'
          SchemaBuilder sb = new(kg);
          sb.Modify(entityDesc);
    
          //Repeat for the relationship - assuming we have at least one custom attribute field
          //that can be deleted on our relationship schema...
          var rel_props = kvp_relate.Value.GetProperties().Reverse().Skip(1).Reverse();
          var rel_prop_descs = new List<KnowledgeGraphPropertyDescription>();
    
          foreach (var prop in rel_props)
          {
            if (prop.FieldType == FieldType.Geometry)
            {
              continue;//skip shape
            }
            var prop_desc = new KnowledgeGraphPropertyDescription(prop);
            rel_prop_descs.Add(prop_desc);
          }
          //deal with shape - we need to keep it
          //SchemaBuilder deletes any field not included in the "modify" list
          ShapeDescription shape_desc_rel = null;
          if (kvp_relate.Value.GetIsSpatial())
          {
            var geom_def = kvp_relate.Value.GetShapeDefinition();
            var shape_name = kvp_relate.Value.GetShapeField();
            shape_desc_rel = new ShapeDescription(
              shape_name, geom_def.geometryType, geom_def.sr);
          }
          //add a new relationship property
          rel_prop_descs.Add(
            KnowledgeGraphPropertyDescription.CreateStringProperty("bar", 10));
          //make a description for the relationship type - ok if shape_desc is null
          var relDesc = new KnowledgeGraphRelationshipTypeDescription(
            relate_name, rel_prop_descs, shape_desc_rel);
    
          //Add the relationship type description to the schema builder using 'Modify'
          sb.Modify(relDesc);
    
          //Run the schema builder
          try
          {
            //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 Modify error: {err_msg}");
            }
          }
          catch (Exception ex)
          {
            System.Diagnostics.Debug.WriteLine(ex.ToString());
          }
        }
      });
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.4 or higher.
    See Also