EntityCollection Sorting in wrong order...!!

Posts   
 
    
BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 11-Mar-2009 12:38:36   

Hello!

Ok.. it seems my day for posting today.

I am hoping this is something I am just doing wrong but it appears that my EntityCollection is sorting in ASC rather than DESC as I have asked it to..

I am using this code to Call back an Entity Collection:



   public static EntityCollection GetLatestTrackingInformationForOrderDetail(Guid orderDetailId)
        {
            EntityCollection orderDetails = new EntityCollection(new JobTicketTrackingEntityFactory());

            IPrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.JobTicketTrackingEntity);
            prefetch.Add(JobTicketTrackingEntity.PrefetchPathDocumentBackCoverTracking);
            prefetch.Add(JobTicketTrackingEntity.PrefetchPathDocumentBodyTracking);
            prefetch.Add(JobTicketTrackingEntity.PrefetchPathDocumentFrontCoverTracking);

            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            bucket.PredicateExpression.Add(JobTicketTrackingFields.OrderDetailId == orderDetailId);
            SortExpression sorter = new SortExpression(JobTicketTrackingFields.DateChanged | SortOperator.Descending);

            using (DataAccessAdapter a = new DataAccessAdapter())
            {
                a.FetchEntityCollection(orderDetails, bucket, 0, sorter, prefetch);
            }

            return orderDetails;

        }


Then calling this via a webservice and using it in a windows form.

In my windows for I do this:

JobTicketTrackingEntity jobTicket = (JobTicketTrackingEntity)orderDetail[0];

to get the entity with the latest date but I am getting the one with the oldest date!

I have used SQL Profiler and it's posting 4 queries and the query for the JobTicketTracking definitly has "Desc" in it, but when I loop the entity collection it's ascending by date not descending!

What on earth is going on?

Thanks

Bex

I am using Adapter, v2.6

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 11-Mar-2009 15:23:18   

I have used SQL Profiler and it's posting 4 queries and the query for the JobTicketTracking definitly has "Desc" in it

This shows that the correct sorting has been done in the database.

Would you please check the sort order in the fetched collection in the webservice side, before sending it to the client (WindiwsForm)?

Which runtime library version are using?