Tuesday 24 February 2015

At least one object must implement IComparable

Currently I had meet a problem as the title above. It is really weird, because I also had use the Group By and toList() function in the other process and not error pop up.

The coding is as below :

//Get the Detail by grouping with article number, color and category.
                
  1. //Get the Detail by grouping with article number, color and category.  
  2. var DetailGroup = detail.GroupBy(c => new { c.ARTICLE_NUMBER, c.COLOR, c.CATEGORY, c.UOM })  
  3. .OrderByDescending(o => new { o.Key.ARTICLE_NUMBER, o.Key.COLOR }).ToList();  
After looking for the online resources, I find this Article and just realize that it maybe is not about the Group By but the Order By (multiple order by in the group by)

So that, I modify a bit the coding (add in ThenBy) :
  1. //Get the Detail by grouping with article number, color and category.  
  2. var DetailGroup = detail.GroupBy(c => new { c.ARTICLE_NUMBER, c.COLOR, c.CATEGORY, c.UOM })  
  3. .OrderByDescending(o =>o.Key.ARTICLE_NUMBER).ThenBy( o =>  o.Key.COLOR ).ToList();  
and it is work fine and faster.


Hope this can help you and have a nice day. :)

--------------------------------------------
This article from: http://oysterleelife.blogspot.sg/2012/11/solved-at-least-one-object-must.html

No comments:

Post a Comment