Query task on SDE layer

341
4
05-10-2011 06:45 AM
MarcoRosa
New Contributor
Hi to all,
i have a layer on arcsde (SQL 2008 R2) and a service who map this layer. I have also a query task with where clausole.
if i would like to make an order by i have an error ( arcmap has the same problem ). This not happens if the service map a layer on file geodatabase. the where clausole i have used is  "1=1 order by myfield", I have tried to do this also whith syntax from sql server 2008
databasename.dbo.layername.fieldname

If where clausole not specified all works good, but i need to apply a order by on field.
That's right ? is a correct behaviour of arcsde layer or there's a way tio do this anyway ?

Thanks very very much
GP
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
"order by" in the Where clause is not something the REST API currently support.

You need to use System.Linq to perform this once QueryTask.ExecuteCompleted.
e.FeatureSet.Features.OrderBy(g => (string)g.Attributes["fieldName"]);

The data type must much your field type. fieldName is your layer field which you want to order by.
0 Kudos
MarcoRosa
New Contributor
Hi jennifer,
i tried to do this but looks like never happens.
The order of elements is the same of original featureclass of sde layer.
It can be ?

QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet _featureSet = args.FeatureSet;

            _featureSet.Features.OrderBy(g => (string)g.Attributes["myfield"]);

            for (int i = 0; i < _featureSet.Features.Count; i++)
            {
                System.Diagnostics.Debug.WriteLine(_featureSet.Features.Attributes["myfield"].ToString());
            }
0 Kudos
by Anonymous User
Not applicable
"order by" in the Where clause is not something the REST API currently support. 

You need to use System.Linq to perform this once QueryTask.ExecuteCompleted. 
e.FeatureSet.Features.OrderBy(g => (string)g.Attributes["fieldName"]);

The data type must much your field type. fieldName is your layer field which you want to order by.


You need to use the result of the order by operation.

 var sortedList = featureSet.Features.OrderBy(f => (string) f.Attributes["STATE_NAME"]).ToList();

            foreach(var graphic in sortedList)
            {
                System.Diagnostics.Debug.WriteLine(graphic.Attributes["STATE_NAME"]);
            }
0 Kudos
MarcoRosa
New Contributor
Thank's a lot
GP
0 Kudos