Select to view content in your preferred language

Linq Sort

1497
12
03-11-2011 12:15 PM
JayKappy
Frequent Contributor
I have been trying to find an answer at Silverlight forums and LINQ forums but no luck....

I can sort by "officer" no problem....but I want to sort by the IncidentNumber field which is numberic...Cant seem to get it to sort...

I tried with no success:

  1. Order By CStr(g.Attributes("IncidentNum")) Ascending

  2. Order By CInt(g.Attributes("IncidentNum")) Ascending

  3. Order By CDbl(g.Attributes("IncidentNum")) Ascending

Works for Officer:       
Dim results2 = From g In featureSet
        Order By CStr(g.Attributes("Officer")) Ascending
        Group g By GroupKey = CStr(g.Attributes("Officer")) Into r = Group
        Select New With {Key .Officer = GroupKey, Key .IncidentNums = r.Sum(Function(i) Convert.ToInt32(i.Attributes("IncidentNum")))}


Does NOT work for IncidentNumber (Map Service Field Name = IncidentNum)
Dim results2 = From g In featureSet
        Order By CStr(g.Attributes("IncidentNum")) Ascending
        Group g By GroupKey = CStr(g.Attributes("Officer")) Into r = Group
        Select New With {Key .Officer = GroupKey, Key .IncidentNums = r.Sum(Function(i) Convert.ToInt32(i.Attributes("IncidentNum")))}
0 Kudos
12 Replies
JayKappy
Frequent Contributor
The Field is an Integer.....

Tried using the actual Attribute field name "IncidentNum", NOTHING ..no sorting

        Dim results2 = From g In featureSet
                        Order By Convert.ToInt32(g.Attributes("IncidentNum")) Descending
                        Group g By GroupKey = DirectCast(g.Attributes("Officer"), String) Into r = Group
                        Select New With {Key .Officer = GroupKey, Key .IncidentNums = r.Sum(Function(i) Convert.ToInt32(i.Attributes("IncidentNum")))}


But then thinking...I am trying to sort the "Key .IncidentNums" being created by Sum, NOTHING ...no sortting...

        Dim results2 = From g In featureSet
                        Order By Convert.ToInt32(g.Attributes("IncidentNums")) Descending
                        Group g By GroupKey = DirectCast(g.Attributes("Officer"), String) Into r = Group
                        Select New With {Key .Officer = GroupKey, Key .IncidentNums = r.Sum(Function(i) Convert.ToInt32(i.Attributes("IncidentNum")))}



Also...but getting errors

Order By Convert.ToInt32(g.Attributes("IncidentNum"), Integer) Descending
Order By Convert.ToInt32(g.Attributes("IncidentNum"), Double) Descending

Order By Convert.ToInt32(g.Attributes("IncidentNums"), Integer) Descending
Order By Convert.ToInt32(g.Attributes("IncidentNums"), Double) Descending
0 Kudos
JenniferNery
Esri Regular Contributor
Before you apply any sort, test that you can successfully perform the conversion.
Dim integerValue As Integer = Convert.ToInt32(g.Attributes("IncidentNum"))


If you can get the above code to work, I don't see why sorting against this value will not work.
0 Kudos
JayKappy
Frequent Contributor
first off once again I thank you with this issue....driving me nuts...I am trying my best which does nto seem to be enough....

problem is that alone g is undefined...I am defining g from the results of the query (featureset)


    Private Sub QueryTaskPolice_ExecuteCompletedListBox(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)

        Dim featureSet As FeatureSet = args.FeatureSet
        Dim results2 = From g In featureSet
                Group g By GroupKey = DirectCast(g.Attributes("Officer"), String) Into r = Group
                Select New With {Key .Officer = GroupKey, Key .IncidentNums = r.Sum(Function(i) Convert.ToInt32(i.Attributes("IncidentNum")))}


If I do this, I get the error that g is undefined...

    Private Sub QueryTaskPolice_ExecuteCompletedListBox(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)

        Dim featureSet As FeatureSet = args.FeatureSet

        Dim integerValue As Integer = Convert.ToInt32(g.Attributes("IncidentNum"))


I then tried..

        Dim integerValue As Integer = Convert.ToInt32(featureSet.Attributes("IncidentNum"))


.Error 1 'Attributes' is not a member of 'ESRI.ArcGIS.Client.Tasks.FeatureSet'.


Then tried this

        Dim results2 = From g In featureSet
        Dim integerValue As Integer = Convert.ToInt32(results2.Attributes("IncidentNum"))


Error 1 'Attributes' is not a member of 'System.Collections.Generic.IEnumerable(Of

uggggggggggggggggg
0 Kudos