Select to view content in your preferred language

QueryRelatedFeaturesAsync returns zero results

375
2
03-18-2022 09:34 AM
MattH
by
Emerging Contributor

I've been trying to call QueryRelatedFeaturesAsync to get related features from a feature service, but it's returning zero results. If I call queryRelatedRecords using Rest with the same ObjectID, I correctly get 38 results.

I was actually getting related features returned at some point last week, but it looks like I'm missing something now.

I've tried a few things:

IdentifyLayerResult results = await esriMap.IdentifyLayerAsync(_myFeatureLayer, e.Position, 10, false);

//correct feature is loaded
ArcGISFeature myFeature; = (ArcGISFeature)results.GeoElements[0];

//returns zero results
IReadOnlyList<RelatedFeatureQueryResult> relatedFeaturesResult =
await myFeatureTable.QueryRelatedFeaturesAsync(myFeature);

 

I tried adding query parameters:

ArcGISFeatureTable myFeatureTable = ArcGISFeatureTable)myFeature.FeatureTable;

//returns the correct relationship info
RelationshipInfo commentsRelationshipInfo = myFeatureTable.LayerInfo.RelationshipInfos.FirstOrDefault();

RelatedQueryParameters relatedQueryParams = new RelatedQueryParameters(commentsRelationshipInfo) { ReturnGeometry = true };

//returns zero results
IReadOnlyList<RelatedFeatureQueryResult> relatedFeaturesResult =
await myFeatureTable.QueryRelatedFeaturesAsync(myFeature, relatedQueryParams);

 

I also tried force loading the feature table:

await myFeature.LoadAsync();
await myFeature.FeatureTable.LoadAsync();

ArcGISFeatureTable myFeatureTable = ArcGISFeatureTable)myFeature.FeatureTable;

//returns the correct relationship info
RelationshipInfo commentsRelationshipInfo = myFeatureTable.LayerInfo.RelationshipInfos.FirstOrDefault();

RelatedQueryParameters relatedQueryParams = new RelatedQueryParameters(commentsRelationshipInfo) { ReturnGeometry = true };

//returns zero results
IReadOnlyList<RelatedFeatureQueryResult> relatedFeaturesResult =
await myFeatureTable.QueryRelatedFeaturesAsync(myFeature, relatedQueryParams);

 

0 Kudos
2 Replies
JoeHershman
MVP Regular Contributor

I've only ever done with offline tables, but you could try to explicitly load the related tables and see if that helps 

var relatedTables = myFeatureTable .GetRelatedTables();
foreach (var relatedTable in relatedTables)
{
	await relatedTable.LoadAsync();
}

var relatedFeaturesResult = await myFeatureTable.QueryRelatedFeaturesAsync(myFeature);
Thanks,
-Joe
0 Kudos
MattH
by
Emerging Contributor

Thank you.

That didn't work directly, but it got me to look in the right place.

At some point, I removed my reference to the related feature layer from the map. I didn't realize that the feature table had to be explicitly added to the map to be found by .QueryRelatedFeaturesAsync()

0 Kudos