ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Core.Data Namespace / Relationship Class
Members Example

In This Topic
    Relationship Class
    In This Topic
    Represents a pair of related rows (or features) from a geodatabase.
    Object Model
    Relationship ClassRow ClassRow Class
    Syntax
    public class Relationship : ArcGIS.Core.CoreObjectsBase, System.IDisposable  
    Public Class Relationship 
       Inherits ArcGIS.Core.CoreObjectsBase
       Implements System.IDisposable 
    Remarks
    A Relationship represents a relationship between rows and/or features where the tables or feature classes must participate in a RelationshipClass. In this type of relationship, there is no intermediate table to store information about the related rows/features. Relationships are created using RelationshipClass.CreateRelationship and are returned using RelationshipClass.GetRowsRelatedToOriginRows or RelationshipClass.GetRowsRelatedToDestinationRows.
    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();
        }
      });
    }
    Inheritance Hierarchy

    System.Object
       ArcGIS.Core.CoreObjectsBase
          ArcGIS.Core.Data.Relationship
             ArcGIS.Core.Data.AttributedRelationship

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also