ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Core.Data Namespace / Geodatabase Class / GetRelatedDefinitions Method
The source from which relationships are searched.
The relationship type constraint used to search for the related dataset definitions.
Example

In This Topic
    GetRelatedDefinitions Method
    In This Topic
    Gets a IReadOnlyList of Definition instances where each one is related to definition by satisfying the relationshipType constraint in the geodatabase. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    definition
    The source from which relationships are searched.
    relationshipType
    The relationship type constraint used to search for the related dataset definitions.

    Return Value

    A list of Definition instances that satisfy the relationshipType.
    Exceptions
    ExceptionDescription
    definition is null.
    No valid geodatabase has been opened prior to calling this operation.
    The version of the geodatabase is pre 10.x.
    A geodatabase-related exception has occurred.
    Remarks
    Currently, this method does not support pre 10.x geodatabases. System.NotSupportedException is thrown if the underlying geodatabase does not meet this requirement.
    Example
    Obtaining Related Definitions from Geodatabase
    public async Task ObtainingRelatedDefinitionsFromGeodatabase()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        {
          // Remember the qualification of DatabaseName. for the RelationshipClass.
    
          RelationshipClassDefinition enterpriseDefinition = geodatabase.GetDefinition<RelationshipClassDefinition>("LocalGovernment.GDB.AddressPointHasSiteAddresses");
          IReadOnlyList<Definition> enterpriseDefinitions = geodatabase.GetRelatedDefinitions(enterpriseDefinition, DefinitionRelationshipType.DatasetsRelatedThrough);
          FeatureClassDefinition enterpriseAddressPointDefinition = enterpriseDefinitions.First(defn => defn.GetName().Equals("LocalGovernment.GDB.AddressPoint"))
            as FeatureClassDefinition;
    
          FeatureDatasetDefinition featureDatasetDefinition = geodatabase.GetDefinition<FeatureDatasetDefinition>("LocalGovernment.GDB.Address");
          IReadOnlyList<Definition> datasetsInAddressDataset = geodatabase.GetRelatedDefinitions(featureDatasetDefinition, DefinitionRelationshipType.DatasetInFeatureDataset);
          FeatureClassDefinition addressPointInAddressDataset = datasetsInAddressDataset.First(defn => defn.GetName().Equals("LocalGovernment.GDB.AddressPoint"))
            as FeatureClassDefinition;
    
          RelationshipClassDefinition addressPointHasSiteAddressInAddressDataset = datasetsInAddressDataset.First(defn => defn.GetName().Equals("LocalGovernment.GDB.AddressPointHasSiteAddresses"))
            as RelationshipClassDefinition;
        }
      });
    }
    Obtaining related Feature Classes from a Relationship Class
    public async Task GetFeatureClassesInRelationshipClassAsync()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\LocalGovernment.gdb"))))
        {
          IReadOnlyList<RelationshipClassDefinition> relationshipClassDefinitions = geodatabase.GetDefinitions<RelationshipClassDefinition>();
    
          foreach (RelationshipClassDefinition relationshipClassDefinition in relationshipClassDefinitions)
          {
            IReadOnlyList<Definition> definitions = geodatabase.GetRelatedDefinitions(relationshipClassDefinition, DefinitionRelationshipType.DatasetsRelatedThrough);
    
            foreach (Definition definition in definitions)
            {
              System.Diagnostics.Debug.WriteLine($"Feature class in the RelationshipClass is:{definition.GetName()}");
            }
          }
        }
      });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also