This document is archived and information here might be outdated.  Recommended version.


IMapServer3.QueryRelatedRecords Method (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference (Carto)  

IMapServer3.QueryRelatedRecords Method

Returns the IDs of the rows that meet the query filter selection criteria for the specified table.

[Visual Basic .NET]
Public Function QueryRelatedRecords ( _
    ByVal MapName As String, _
    ByVal sourceTable As Integer, _
    ByVal pFIDs As IFIDSet, _
    ByVal RelateDescription As IRelateDescription _
) As IQueryResult
[C#]
public IQueryResult QueryRelatedRecords (
    string MapName,
    int sourceTable,
    IFIDSet pFIDs,
    IRelateDescription RelateDescription
);
[C++]
HRESULT QueryRelatedRecords(
  BSTR MapName,
  long sourceTable,
  IFIDSet* pFIDs,
  IRelateDescription* RelateDescription
);
[C++]

Parameters MapName [in]
MapName is a parameter of type BSTR sourceTable [in]
sourceTable is a parameter of type long pFIDs [in]
pFIDs is a parameter of type IFIDSet* RelateDescription [in]
RelateDescription is a parameter of type IRelateDescription*

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Remarks

When esriRelateResultRelatedRecordSetAsObject is selected as ResultFormat, the function returns RelatedRecordSet embedded within a QueryResult. Use QueryResult.Object to get RelatedRecordSet.

An FIDSet needs to be created and assign an array of ObjectID to FIDArray property. Related records for ObjectID(s) contained by FIDSet will be queried. Typically this function follows QueryData, in that case you can use values of OIDField from the returned RecordSet to populate FIDSet.

RelateDescription contains information about relationship that will be explored. RelateDescription needs to be created and populated with relates ID, list of fields and output result format. In case where both RelatedTableFields and IncludeGeometry is set, RelatedTableFields takes precedence over IncludeGeometry. For example, when RelatedTableFields=“Shape, FName, LName, Address” and IncludeGeometry=False, the output recordset will contain geometry as contained within the Shape field.

When more than one ObjectID is passed, use SourceRowID to relate ‘related rows’ back to the source feature or row.

The result honors the fields visibility set in the layer or the standalone table.

 

Output Spatial and Time Reference

If the desired spatial reference of the output geometry is different than the original one, OutputSpatialReference should be used. Otherwise geometry is returned in the same spatial reference system as the DefaultMapDescription by default.

Values in StartTimeField or EndTimeField are returned in the Layer's TimeReference. If the desired time reference is different than the layer's one, OutputTimeReference should be explicitly set.

 

Relates with non GeoDatabase Tables

Since QueryRelatedRecords relies on IDs of features or rows from the source layer/table, when a table does not have an OIDField (not a Geodatabase table), finding related records from the source layer/table from the destination table is not possible. For example, when a Parcel layer is related to a Owership table (for example from an Oracle database), you may find related ownership information for a parcel, but the function does not allow to find parcels belong to a owner. In order to traverse the other way a table must have a OIDField. You may consider one of the following options for this type of scenario:

 

Please note that retrieving related rows that has joins may impact the performance.

[C#]

For example, LayerA (LayerID=1) is related to TableB (StandaloneTableID=2) and you want to find all rows in TableB related to a feature in LayerA whose ObjectID is 3. In this case, you need to do the followings:

Step 1: create a RelateDescription and populate information
RelateDescription pRD=new RelateDescription();
pRD.RelationshipID=2;
pRD.RelatedTableFields=“*”; //or you can a pass a subset of fields
pRD.ResultFormat=esriRelateResultFormat.esriRelateResultRelatedRecordSetAsObject;

 

Step 2: create a FIDSet
int[] intOIDs=new int[1] {3};
FIDSet pSrcFIDSet=new FIDSet();
pSrcFIDSet.FIDArray=intOIDs;


Step 3: execute the function
QueryResult pQR=QueryRelatedRecords(aMapName, 1, pSrcFIDSet, pRD);

 

Step 4: get result
RelatedRecordSet pRelRecordSet=pQR.Object;
/* number of elements in RelatedRecordGroups matches with number of ObjectID passed in as SourceFIDSet */
RelatedRecordGroup pRelRecGroup=RelatedRecordGroups[0];
Console.WriteLine(“Feature with ObjectID=” + pRelRecGroup.SourceRowID.toString()); //object id of the source feature
Console.WriteLine(“has “ + pRelRecGroup.Records.length.toString() + “ related rows”);

 

See Also

IMapServer3 Interface