ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Core.Data Namespace / Table Class / RelateTo Method
The Table or FeatureClass which acts as the destination of the resulting relationship class.
The VirtualRelationshipClassDescription which describes the properties with which the relationship class is created.
Example

In This Topic
    RelateTo Method
    In This Topic
    Creates a virtual relationship class with the current table as the origin table/feature class and the destinationTable as the destination table/feature class. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    destinationTable
    The Table or FeatureClass which acts as the destination of the resulting relationship class.
    description
    The VirtualRelationshipClassDescription which describes the properties with which the relationship class is created.

    Return Value

    The virtual RelationshipClass created from the destinationTable and description.
    Exceptions
    ExceptionDescription
    destinationTable or description is null.
    A geodatabase-related exception has occurred.
    Remarks
    The resulting RelationshipClass will not be persisted in the data store. Typically, it is used as an input to JoinDescription in order to create a Join object.
    Example
    Joining a file geodatabase feature class to an Oracle database query layer feature class with a virtual relationship class
    public async Task JoiningFileGeodatabaseFeatureClassToOracleQueryLayer()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri("C:\\Data\\LocalGovernment.gdb"))))
        using (Database database = new Database(new DatabaseConnectionProperties(EnterpriseDatabaseType.Oracle)
        {
          AuthenticationMode = AuthenticationMode.DBMS,
          Instance = "instance",
          User = "user",
          Password = "password",
          Database = "database"
        }))
    
        using (FeatureClass leftFeatureClass = geodatabase.OpenDataset<FeatureClass>("Hospital"))
        using (Table rightTable = database.OpenTable(database.GetQueryDescription("FacilitySite")))
        {
          Field originPrimaryKey = leftFeatureClass.GetDefinition().GetFields().FirstOrDefault(field => field.Name.Equals("facilityId"));
          Field destinationForeignKey = rightTable.GetDefinition().GetFields().FirstOrDefault(field => field.Name.Equals("hospitalID"));
    
          VirtualRelationshipClassDescription description = new VirtualRelationshipClassDescription(
            originPrimaryKey, destinationForeignKey, RelationshipCardinality.OneToOne);
    
          using (RelationshipClass relationshipClass = leftFeatureClass.RelateTo(rightTable, description))
          {
            JoinDescription joinDescription = new JoinDescription(relationshipClass)
            {
              JoinDirection = JoinDirection.Forward,
              JoinType = JoinType.LeftOuterJoin
            };
    
            Join join = new Join(joinDescription);
    
            using (Table joinedTable = join.GetJoinedTable())
            {
              // Perform operation on joined table.
            }
          }
        }
      });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also