When Ordering custom collection in Linq using multiple fields you can use OrderBy and ThenBy methods.
Example
private BOMLineDTO[] SortBOMLines(BOMLineDTO[] bomLines)Here BOMLineComparer<T> is My own class which is derived form IComparer<T> interface
{
BOMLineDTO[] sortedBOMLines = null;
if (null != bomLines)
{
sortedBOMLines = bomLines.OrderBy(record => record.ItemDescription, new BOMLineComparer<StringField>()).
ThenBy(record => record.BOMCategoryType, new BOMLineComparer<BasicDataField>()).
ThenBy(record => record.GMTColor, new BOMLineComparer<BasicDataField>()).
ThenBy(record => record.GMTSize, new BOMLineComparer<BasicDataField>()).ToArray();
}
return sortedBOMLines;
}
Related Posts:http://prabodha-eranga.blogspot.com/2012/05/linq-orderby-custom-comparer.html
No comments:
Post a Comment