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?
Solved! Go to Solution.
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.
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.