Sunday, August 21, 2011

.OrderBy

This is an example of .OrderBy

var foo = whatever.ToList().OrderBy(x => x.Name);

 
 

Here is a more sophisticated example I found here.

var sorted = model.Products.OrderBy(x => x.ProductName).ThenBy(x=>x.ProductID);

 
 

I found this stuff while trying to sort not a List<T> but instead a PagedList<T>. This suggests there is some bugginess in sorting a PagedList<T>. I find myself struggling to implement .OrderBy on a PagedList itself. I am struggling to figure out what I am supposed to pass in. I also am struggling to figure out how to just cast everything in a PagedList back out to an IEnumerable. Whatever. Maybe I should just message things before passing them into PagedLists and not expect to ever pull stuff back out.

No comments:

Post a Comment