Select to view content in your preferred language

Issue on Getting Attributes at Query Only in ArcGIS Runtime SDK for .NET

791
1
Jump to solution
03-31-2017 03:39 PM
BehrouzHosseini
Regular Contributor

Trying to Query an ESRI MapService through ArcGIS Runtime .NET SDK 10.2.7 (Using this sample)

 private async void QueryButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                await RunQuery();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }
        private async Task RunQuery()
        {
            try
            {
                QueryTask queryTask = new QueryTask(
                    new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"));

                Query query = new Query(StateNameTextBox.Text);
                query.OutFields.Add("STATE_NAME");

                var result = await queryTask.ExecuteAsync(query);
               itemListView.ItemsSource = result.FeatureSet.Features.OrderBy(g => g.Attributes["STATE_NAME"]);
            }
            catch (TaskCanceledException) { }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }
    }

but in result I am getting Esri.ArcGISRuntime.Layers.Graphic instead of the name of the states!

Can you please let me know why this is happening and how can I fix it?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
GregDeStigter
Esri Contributor

I think you're missing a `Select` on your Linq statement. Try this:

itemListView.ItemsSource = result.FeatureSet.Features.OrderBy(g => g.Attributes["STATE_NAME"])
.Select(g => g.Attributes["STATE_NAME"]);

That should give you the state name attributes instead of the actual Graphic / Feature containers.

View solution in original post

0 Kudos
1 Reply
GregDeStigter
Esri Contributor

I think you're missing a `Select` on your Linq statement. Try this:

itemListView.ItemsSource = result.FeatureSet.Features.OrderBy(g => g.Attributes["STATE_NAME"])
.Select(g => g.Attributes["STATE_NAME"]);

That should give you the state name attributes instead of the actual Graphic / Feature containers.

0 Kudos