var relFtrs = await table.QueryRelatedFeaturesAsync (ftr as ArcGISFeature);
foreach (RelatedFeatureQueryResult r in relFtrs) {
//Get the feature and load the attributes
???
//This is the original feature passed into QueryRelatedFeaturesAsync
var originalFtr = r.Feature;
//This gets set to the expected related table
var relatedTable = r.RelatedTable;
//The KeyField property of this is the field name of the original feature key field
var relInfo = r.RelationshipInfo;
//These are the fields from the expected related table
var flds = r.Fields;
}
I'd be interested to hear if anyone has gotten this working, as it appears in the cases I have been trying that this code is not working (although I'm also totally confused at the implementation of this).
Issues:
- I get a collection of objects returned from QueryRelatedFeaturesAsync, but it is not clear how to get the actual related feature / attributes.
- The originalFtr above is the feature object passed into QueryRelatedFeaturesASync. Is this by design I wonder?
- The RelatedTable is correct, so I thought I could use the RelationshipInfo to just manually get the related records, but the KeyField property is the original feature field not, not the field name needed for the RelatedTable. Why not just provide the foreign key field here??
- The Fields are the correct fields, the ones expected from the RelatedTable.
- I could get the RelatedTableId from the RelationshipInfo, but that's the Id in that specific dataset, so if you have mixed data (online and runtime content), then you'll get the wrong layer. Even if I get the layer, I don't know the key field?!?
Any feedback or comments would be greatly appreciated. Something that should have been a simple task has turned into much more of a production to implement. Maybe I'm missing something though, I sure hope so....
Thanks.
Solved! Go to Solution.
What is returned is a collection within a collection. The RelatedFeatureQueryResult object is an Enumerable of the related objects grouped by related table.
private async Task<RelatedFeatureQueryResult> QueryForRelatedBarholesAsync(ArcGISFeature feature)
{
var gdbFeatureTable = (GeodatabaseFeatureTable) feature.FeatureTable;
var queryResults = await gdbFeatureTable.QueryRelatedFeaturesAsync(feature);
var relatedBarholeResults = queryResults.FirstOrDefault(
r => r.RelatedTable.TableName.Equals(TableNames.Barhole, StringComparison.CurrentCultureIgnoreCase));
return relatedBarholeResults;
}
The call to QueryRelatedFeaturesAsync gets all the features related to that feature. In the code above the TableName is used to find the result set for the related table we are interested in. The RelatedFeatureQueryResult is what you are really after..
RelatedFeatureQueryResult relatedBarholeResults = await QueryForRelatedBarholesAsync(gasLeakFeature);
if ( relatedBarholeResults == null ) return;
foreach (var barholeFeature in relatedBarholeResults.OfType<ArcGISFeature>())
{
//do something with the features
}
What is returned is a collection within a collection. The RelatedFeatureQueryResult object is an Enumerable of the related objects grouped by related table.
private async Task<RelatedFeatureQueryResult> QueryForRelatedBarholesAsync(ArcGISFeature feature)
{
var gdbFeatureTable = (GeodatabaseFeatureTable) feature.FeatureTable;
var queryResults = await gdbFeatureTable.QueryRelatedFeaturesAsync(feature);
var relatedBarholeResults = queryResults.FirstOrDefault(
r => r.RelatedTable.TableName.Equals(TableNames.Barhole, StringComparison.CurrentCultureIgnoreCase));
return relatedBarholeResults;
}
The call to QueryRelatedFeaturesAsync gets all the features related to that feature. In the code above the TableName is used to find the result set for the related table we are interested in. The RelatedFeatureQueryResult is what you are really after..
RelatedFeatureQueryResult relatedBarholeResults = await QueryForRelatedBarholesAsync(gasLeakFeature);
if ( relatedBarholeResults == null ) return;
foreach (var barholeFeature in relatedBarholeResults.OfType<ArcGISFeature>())
{
//do something with the features
}
Wow, thanks Joe, that was confusing the you know what out of me.
While this doesn't seem close to what Esri has in their samples or documentation, I do see what you mean now and can get to the actual features. Doesn't seem like best implementation to me, but at least it does seem to work.
Thanks so much for your time and help, it is much appreciated.