ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Core.Data Namespace / RelationshipClassDefinition Class / GetOriginKeyField Method
Example

In This Topic
    GetOriginKeyField Method
    In This Topic
    Gets the name of the origin (primary) key field. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public string GetOriginKeyField()
    Public Function GetOriginKeyField() As String

    Return Value

    The name of the origin (primary) key field.
    Exceptions
    ExceptionDescription
    A geodatabase-related exception has occurred.
    Example
    Creating a Relationship
    public async Task CreatingARelationship()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file"))))
        using (RelationshipClass relationshipClass = geodatabase.OpenDataset<RelationshipClass>("LocalGovernment.GDB.OverviewToProject"))
        using (FeatureClass projectsFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.CIPProjects"))
        using (FeatureClass overviewFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.CIPProjectsOverview"))
        {
          // This will be PROJNAME. This can be used to get the field index or used directly as the field name.
          string originKeyField = relationshipClass.GetDefinition().GetOriginKeyField();
    
          EditOperation editOperation = new EditOperation();
          editOperation.Callback(context =>
          {
            // The rows are being added to illustrate adding relationships. If one has existing rows, those can be used to add a relationship.
            using (RowBuffer projectsRowBuffer = projectsFeatureClass.CreateRowBuffer())
            using (RowBuffer overviewRowBuffer = overviewFeatureClass.CreateRowBuffer())
            {
              projectsRowBuffer["TOTCOST"] = 500000;
    
              overviewRowBuffer[originKeyField] = "LibraryConstruction";
              overviewRowBuffer["PROJECTMAN"] = "John Doe";
              overviewRowBuffer["FUNDSOUR"] = "Public";
    
              using (Row projectsRow = projectsFeatureClass.CreateRow(projectsRowBuffer))
              using (Row overviewRow = overviewFeatureClass.CreateRow(overviewRowBuffer))
              {
                Relationship relationship = relationshipClass.CreateRelationship(overviewRow, projectsRow);
    
                //To Indicate that the Map has to draw this feature/row and/or the attribute table has to be updated
                context.Invalidate(projectsRow);
                context.Invalidate(overviewRow);
                context.Invalidate(relationshipClass);
              }
            }
          }, projectsFeatureClass, overviewFeatureClass);
    
          bool editResult = editOperation.Execute();
        }
      });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also