ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Editing Namespace / EditOperation Class / Create Method / Create(Table,Dictionary<String,Object>) Method
The table to create the new row in.
The attributes to assign the new row.
Example

In This Topic
    Create(Table,Dictionary<String,Object>) Method
    In This Topic
    Creates a new row with the given attributes.
    Syntax
    Public Overloads Function Create( _
       ByVal table As Table, _
       ByVal values As Dictionary(Of String,Object) _
    ) As RowToken

    Parameters

    table
    The table to create the new row in.
    values
    The attributes to assign the new row.

    Return Value

    A RowToken object that represents the row to be created.
    Example
    Create a record in a separate table in the Map within Row Events
    // Use the EditOperation in the RowChangedEventArgs to append actions to be executed. 
    //  Your actions will become part of the operation and combined into one item on the undo stack
    
    private void HookRowCreatedEvent()
    {
      // subscribe to the RowCreatedEvent
      Table table = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault().GetTable();
      RowCreatedEvent.Subscribe(MyRowCreatedEvent, table);
    }
    
    private void MyRowCreatedEvent(RowChangedEventArgs args)
    {
      // RowEvent callbacks are always called on the QueuedTask so there is no need 
      // to wrap your code within a QueuedTask.Run lambda.
    
      // get the edit operation
      var parentEditOp = args.Operation;
    
      // set up some attributes
      var attribs = new Dictionary<string, object> { };
      attribs.Add("Layer", "Parcels");
      attribs.Add("Description", "OID: " + args.Row.GetObjectID().ToString() + " " + DateTime.Now.ToShortTimeString());
    
      //create a record in an audit table
      var sTable = MapView.Active.Map.FindStandaloneTables("EditHistory").First();
      var table = sTable.GetTable();
      parentEditOp.Create(table, attribs);
    }
    Create a record in a separate table within Row Events
    // Use the EditOperation in the RowChangedEventArgs to append actions to be executed. 
    //  Your actions will become part of the operation and combined into one item on the undo stack
    
    private void HookCreatedEvent()
    {
      // subscribe to the RowCreatedEvent
      Table table = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault().GetTable();
      RowCreatedEvent.Subscribe(OnRowCreatedEvent, table);
    }
    
    private void OnRowCreatedEvent(RowChangedEventArgs args)
    {
      // RowEvent callbacks are always called on the QueuedTask so there is no need 
      // to wrap your code within a QueuedTask.Run lambda.
    
      // update a separate table not in the map when a row is created
      // You MUST use the ArcGIS.Core.Data API to edit the table. Do NOT
      // use a new edit operation in the RowEvent callbacks
      try
      {
        // get the edit operation
        var parentEditOp = args.Operation;
    
        // set up some attributes
        var attribs = new Dictionary<string, object> { };
        attribs.Add("Description", "OID: " + args.Row.GetObjectID().ToString() + " " + DateTime.Now.ToShortTimeString());
    
        // update Notes table with information about the new feature
        using (var geoDatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(Project.Current.DefaultGeodatabasePath))))
        {
          using (var table = geoDatabase.OpenDataset<Table>("Notes"))
          {
            parentEditOp.Create(table, attribs);
          }
        }
      }
      catch (Exception e)
      {
        MessageBox.Show($@"Error in OnRowCreated for OID: {args.Row.GetObjectID()} : {e.ToString()}");
      }
    }
    Create a new Entity
    await QueuedTask.Run(() =>
    {
    
      //Instantiate an operation for the Create
      var edit_op = new EditOperation()
      {
        Name = "Create a new organization",
        SelectNewFeatures = true
      };
    
      //Use datasets or feature layer(s) or standalone table(s)
      //Get a reference to the KnowledgeGraph
      //var kg = ... ; 
    
      //Open the feature class or Table to be edited
      var org_fc = kg.OpenDataset<FeatureClass>("Organization");
    
      //Alternatively, use the feature layer for 'Organization' if your context is a map
      //Get the parent KnowledgeGraphLayer
      var kg_layer = mv.Map.GetLayersAsFlattenedList()?
                    .OfType<ArcGIS.Desktop.Mapping.KnowledgeGraphLayer>().First();
      //From the KG Layer get the relevant child feature layer
      var org_fl = kg_layer.GetLayersAsFlattenedList().OfType<FeatureLayer>()
                      .First(child_layer => child_layer.Name == "Organization");
    
      //Define attributes
      var attribs = new Dictionary<string, object>();
      attribs["Name"] = "Acme Ltd.";
      attribs["Description"] = "Specializes in household items";
      attribs["SHAPE"] = org_location;
    
      //Add it to the operation via the dataset...
      edit_op.Create(org_fc, attribs);
      //or use the feature layer/stand alone table if preferred and available
      //edit_op.Create(org_fl, attribs);
    
      if (edit_op.Execute())
      {
        //TODO: Operation succeeded
      }
    
    });
    Create a new Relationship from Existing Entities 1
    var create_rel = await QueuedTask.Run(() =>
    {
      //Instantiate an operation for the Create
      var edit_op = new EditOperation()
      {
        Name = "Create a new relationship record",
        SelectNewFeatures = true
      };
    
      //Use datasets or feature layer(s) or standalone table(s)
      //Get a reference to the KnowledgeGraph
      //var kg = ... ; 
    
      //We will use a relate called 'HasEmployee' to relate an Organization w/ a Person
      //Use either tables or map members to get the rows to be related...
      var org_fc = kg.OpenDataset<FeatureClass>("Organization");
      var person_tbl = kg.OpenDataset<Table>("Person");
    
      //Get the relationship dataset
      //We can use either a table or standalone table
      var emp_tbl = kg.OpenDataset<Table>("HasEmployee");
    
      //we need the names of the origin and destination relationship properties
      var kg_prop_info = kg.GetPropertyNameInfo();
    
      //Arbitrarily use the first record from the two entity datasets "to be" related
      //Entities are always related by Global ID. Origin to Destination specifies the
      //direction (of the relate).
      //
      //Populate the attributes for the relationship
      var attribs = new Dictionary<string, object>();
    
      using (var rc = org_fc.Search())
      {
        if (rc.MoveNext())
          //Use the KnowledgeGraphPropertyInfo to avoid hardcoding...
          attribs[kg_prop_info.OriginIDPropertyName] = rc.Current.GetGlobalID();
      }
      using (var rc = person_tbl.Search())
      {
        if (rc.MoveNext())
          //Use the KnowledgeGraphPropertyInfo to avoid hardcoding...
          attribs[kg_prop_info.DestinationIDPropertyName] = rc.Current.GetGlobalID();
      }
    
      //Add any extra attribute information for the relation as needed
      attribs["StartDate"] = new DateTimeOffset(DateTime.Now);
    
      //Add a create for the relationship to the operation
      edit_op.Create(emp_tbl, attribs);
    
      //Do the create
      return edit_op.Execute();
    });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also