ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Core.Data Namespace / Join Class / GetJoinedTable Method
Example

In This Topic
    GetJoinedTable Method
    In This Topic
    Gets the Table representing the join. This provides access to perform operations like Search and Select on the joined data. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public Table GetJoinedTable()
    Public Function GetJoinedTable() As Table

    Return Value

    The Table representing the join.
    Exceptions
    ExceptionDescription
    A geodatabase-related exception has occurred.
    Remarks
    The Table returned by this routine is a virtual one. Calling Table.GetDefinition on this table is not supported and will result in an exception.
    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.
            }
          }
        }
      });
    }
    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.
            }
          }
        }
      });
    }
    Joining two tables from different geodatabases
    public async Task JoinTablesFromDifferentGeodatabases()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase sourceGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri("Path \\ to \\Geodatabase \\ one"))))
        using (Geodatabase destinationGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri("Path \\ to \\Geodatabase \\ two"))))
        using (Table sourceTable = sourceGeodatabase.OpenDataset<Table>("State"))
        using (Table destinationTable = destinationGeodatabase.OpenDataset<Table>("Cities"))
        {
          Field primaryKeyField = sourceTable.GetDefinition().GetFields().FirstOrDefault(field => field.Name.Equals("State.State_Abbreviation"));
          Field foreignKeyField = destinationTable.GetDefinition().GetFields().FirstOrDefault(field => field.Name.Equals("Cities.State"));
    
          VirtualRelationshipClassDescription virtualRelationshipClassDescription = new VirtualRelationshipClassDescription(primaryKeyField, foreignKeyField, RelationshipCardinality.OneToMany);
    
          using (RelationshipClass relationshipClass = sourceTable.RelateTo(destinationTable, virtualRelationshipClassDescription))
          {
            JoinDescription joinDescription = new JoinDescription(relationshipClass)
            {
              JoinDirection = JoinDirection.Forward,
              JoinType = JoinType.InnerJoin,
              TargetFields = sourceTable.GetDefinition().GetFields()
            };
    
            using (Join join = new Join(joinDescription))
            {
              Table joinedTable = join.GetJoinedTable();
    
              //Process the joined table. For example ..
              using (RowCursor cursor = joinedTable.Search())
              {
                while (cursor.MoveNext())
                {
                  using (Row row = cursor.Current)
                  {
                    // Use Row
                  }
                }
              }
            }
          }
        }
      });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also