EntityView2 not sorting

Posts   
 
    
Posts: 94
Joined: 23-Aug-2006
# Posted on: 05-Dec-2012 19:48:54   

I'm using LLBLGen v 3.5 Maybe I've set this up incorrectly but the following code should sort on a Date field - but it doesn't seem to. At the same time it executes without complaint. Odd.


//convert collection to view 
EntityView2<CapsOutputEntity> view = new EntityView2<CapsOutputEntity>(colCapsOutput);

// apply filter
 IPredicateExpression filter = new PredicateExpression(CapsOutputFields.Ssn == capsEntity.Ssn);
                    view.Filter = filter;

// apply sort
 ISortExpression sorter = new SortExpression(CapsOutputFields.DworkStart | SortOperator.Ascending);
                    view.Sorter = sorter;  



The property of the entity in question here is a DateTime type


public virtual Nullable<System.DateTime> DworkStart

Any suggestions of what I might try?

Thanks Thomas

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 05-Dec-2012 21:43:32   

How did you examine the sorting effect? Did you check the original collection or the EntityView?

Posts: 94
Joined: 23-Aug-2006
# Posted on: 05-Dec-2012 23:20:42   

I stumbled on it when I noticed an incorrect value was being processed based on the supposed sort order. Then I used the debug visualizer to look at the SD.LLBLGen.Pro.ORMSupportClasses.IEntityView2.RelatedCollection = {Collection of entities of type 'CapsOutputEntity'. Current number of elements: 9} of the view.

Is there another way to filter / sort the collection - maybe using linq, as opposed to turning it into a view first. I just need to massage the data in memory a little for iteration, not for binding.

Thanks TW

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 06-Dec-2012 21:09:53   

Sure you can use Linq, but I suggest to look into the "view" itself in the debugger.

Posts: 94
Joined: 23-Aug-2006
# Posted on: 06-Dec-2012 22:04:47   

I thought thats exactly what I was doing and describing in my previous message.... Anyways I have abandoned the view and used linq to get me the same information. This question can be closed.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Dec-2012 07:07:12   

Good! However, these kind of issues usually have to do with what you do with the involved data. Are you modifying the collection after you create the view or are you doing some loop to add/remove entities from the collection? For more info see View behavior on collection changes.

Related threads: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=11958&StartAtMessage=0&#66561

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 07-Dec-2012 10:46:10   

Also: the view is sorted, but not the collection. The view sorts its indexes into the collection, so when you enumerate the view, you get the data in the order / filtered by the filter requested. the collection itself is untouched.

It's unclear to me what you tried: using the view to sort the collection, or use the view to enumerate the data (so not touching the collection)

Frans Bouma | Lead developer LLBLGen Pro
Posts: 94
Joined: 23-Aug-2006
# Posted on: 07-Dec-2012 20:15:48   

When you debug the view and drill into its debug information, how do you see the sorted / filtered data? The only parts of the view object that seemed to contain any data was the RelatedCollection property. Maybe that was my problem all along - looking in the wrong spot. Is the only way to see the view's data to enumerate it ?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Dec-2012 07:24:32   

The EntityView is a list by itself, so just enumerate it. Use the immediate window, or test it in a console app that write down the results to the output.

David Elizondo | LLBLGen Support Team
Posts: 94
Joined: 23-Aug-2006
# Posted on: 08-Dec-2012 16:56:14   

Will do. Thanks. Guess I was so used to checking the LLBLGen debug visualizer for data I reached for that first. Appreciate the feedback.