Retrieve records from related table in ArcGIS Runtime SDK for .NET

4727
20
Jump to solution
07-25-2017 07:01 AM
MiriEshel
New Contributor III

Hi everybody,

We are using ArcGIS Runtime 100.1 and we want to retrieve records from a related table in a FeatureService.

We are able to perform QueryRelatedFeaturesAsync and get the number of features by using NumberOfFeatures but we cannot find any method/property to retrieve the data itself.

Here is the code we are using:

// Select the features based on query parameters defined above
var selectedFeatures = await idLayer.SelectFeaturesAsync(queryParams, Esri.ArcGISRuntime.Mapping.SelectionMode.New);
var feature = selectedFeatures.First() as ArcGISFeature;
var relatedResult = await table.QueryRelatedFeaturesAsync(feature);
var relatedTbl = relatedResult[0].RelatedTable;

var num = relatedTbl.NumberOfFeatures;

What next??

Thanks a lot,

Miri

0 Kudos
20 Replies
ChadYoder1
Occasional Contributor II

Hi Jennifer, I managed to track down my issue and wanted to let you and others know in case they encounter a similar issue.  Basically, the layers I add to the map come from a configuration, so we don't know what or how many runtime content geodatabases will exist.  So, in the simple example I provided you, we might have parcels, property data and centerline.  But, if you use the following code, QueryRelatedFeaturesAsync will never return the relationships (opening the Gdb from within the for loop):

           //List of layers to add to the map
             var layerList = new Dictionary<string, string> {
                 { "Parcels", "palmbeach.geodatabase" },
                 {"condodata", "palmbeach.geodatabase" },
                 {"CENTERLINE", "centerline.geodatabase" },
                 {"propertydata", "palmbeach.geodatabase" },
                 {"SITUS_PUB", "palmbeach.geodatabase" }
             };
 
             //Iterate and add the layers
             foreach (var layer in layerList) {
                 //Get the GDB path and open the geodatabase
                 string gdbPath = Path.Combine (ConfigurationManager.AppSnapshotsDirectory, layer.Value);
                 gdbPath = PathHelpers.CleanPath (gdbPath);
                 var gdb = await Geodatabase.OpenAsync (gdbPath);
 
                 //Get the table to add to the map
                 var table = gdb.GeodatabaseFeatureTable (layer.Key);
                 if (table != null) {
                     //Load the table and add to the map
                     await table.LoadAsync ();
                     if (table.HasGeometry) {
                         EsriMapView.Map.OperationalLayers.Add (new FeatureLayer (table));
                     } else {
                         EsriMapView.Map.Tables.Add (table);
                     }
                 }
             }    

 But, if you use the following code, which caches the geodatabase, then relationships will work:

            //List of layers to add to the map
             var layerList = new Dictionary<string, string> {
                 { "Parcels", "palmbeach.geodatabase" },
                 {"condodata", "palmbeach.geodatabase" },
                 {"CENTERLINE", "centerline.geodatabase" },
                 {"propertydata", "palmbeach.geodatabase" },
                 {"SITUS_PUB", "palmbeach.geodatabase" }
             };
 
             //Create a dictionary to cache the Gdb
             var gdbList = new Dictionary<string, Geodatabase> ();
 
             //Iterate and add the layers
             Geodatabase gdb = null;
             foreach (var layer in layerList) {
                 //Check for the Gdb in the list
                 if (!gdbList.ContainsKey (layer.Value)) {
                     //Get the GDB path and open the geodatabase
                     string gdbPath = Path.Combine (ConfigurationManager.AppSnapshotsDirectory, layer.Value);
                     gdbPath = PathHelpers.CleanPath (gdbPath);
                     gdb = await Geodatabase.OpenAsync (gdbPath);
 
                     //Add to the cache list of Gdb's
                     gdbList.Add (layer.Value, gdb);
                 } else {
                     gdbList.TryGetValue (layer.Value, out gdb);
                 }
 
                 //Get the table to add to the map
                 var table = gdb.GeodatabaseFeatureTable (layer.Key);
                 if (table != null) {
                     //Load the table and add to the map
                     await table.LoadAsync ();
                     if (table.HasGeometry) {
                         EsriMapView.Map.OperationalLayers.Add (new FeatureLayer (table));
                     } else {
                         EsriMapView.Map.Tables.Add (table);
                     }
                 }
             }

I guess I was thinking that the Geodatabase would be cached, but it doesn't appear to be the case.  Is this expected behavior?  Regardless, probably a bit better for performance this way so we don't have to open the geodatabase multiple times.

0 Kudos