Select to view content in your preferred language

Querying Distinct Values

3558
6
07-14-2010 07:40 AM
RobertMEIER
Regular Contributor
I know that I have to so some kind of LINQ query on the returned featureset similar to this

Dim sortedGraphics As IOrderedEnumerable(Of Graphic) = args.FeatureSet.Features.OrderBy(Function(g) g.Attributes("CONTRACT"))

But when I try this:

Dim sortedGraphics As IOrderedEnumerable(Of Graphic) = args.FeatureSet.Features.Distinct(Function(g) g.Attributes("CONTRACT"))

I get an error.

Lambda expression cannot be converted to 'System.Collections.Generic.IEqualityComparer(Of ESRI.ArcGIS.Client.Graphic)' because 'System.Collections.Generic.IEqualityComparer(Of ESRI.ArcGIS.Client.Graphic)' is not a delegate type.

Any help would be great. I'm just trying to populate a combobox with unique values

-Bert
0 Kudos
6 Replies
RobertMEIER
Regular Contributor
I guess I just had to dig deeper into LINQ queries. Here is the  code I used, I found it by googling around

        Dim unqVals = From featx In args.FeatureSet Distinct _
                           Where featx.Attributes("CONTRACT") <> "" _
                           Select featx.Attributes("CONTRACT") Distinct

        For Each sVal As String In unqVals
            Dim cbItem As New ComboBoxItem
            cbItem.Content = sVal
            cbxContract.Items.Add(cbItem)
        Next

-bert
0 Kudos
JackCibor
Frequent Contributor
Does anyone have a similar example for C#??
0 Kudos
JenniferNery
Esri Regular Contributor
0 Kudos
JackCibor
Frequent Contributor
In these examples the distinct values are  derived from the results of a query task returning the entire dataset to the client. The database I need to return the values for has 40,000 records in it. Does anyone have experience/ideas on doing this on the server side so just the unique values are returned to the client.
0 Kudos
JenniferNery
Esri Regular Contributor
I think your question is best directed to the ArcGIS Server team.

You may find this blog post useful too: http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2010/08/30/Populate-a-combo-box-with-unique-val...
0 Kudos
JohnFletcher
Occasional Contributor
In these examples the distinct values are  derived from the results of a query task returning the entire dataset to the client. The database I need to return the values for has 40,000 records in it. Does anyone have experience/ideas on doing this on the server side so just the unique values are returned to the client.


The following blog post also may be of interest to you - it specifically mentions ArcIMS but still is somewhat applicable:

http://blog.geocortex.com/2008/09/11/bending-the-rules/

The truly efficient method of doing this with ArcIMS that the blog post talks about is not likely to be available through the REST api and therefore the Silverlight client (I think the "feature" was even disabled in later ArcIMS versions) but the first method mentioned there still can be speedier than retrieving all records in one fell swoop, particularly when that number of records is quite large.
0 Kudos