IList (Of T). Sports Aid

Dim classCodeDetails As List(Of ClassCodeDetail) =     
    db.ClassCodeHeaders.Single(Function(cch)
        cch.CLCH_ID = classCodeHeaderId
    ).ClassCodeDetails.ToList()

classCodeDetails.Sort(Function(c1, c2)  
    c1.Make.MAKE_English.CompareTo(c2.Make.MAKE_English)
)

      

My question is, how can I sort by multiple attributes? I want to sort by first Make.MAKE_English

, then by Model.MODL_English

.

How to implement this?

Thank you
~ Sk

+1


a source to share


1 answer


If you don't need to sort in place, you can use the function OrderBy

:

Dim sortedList = list.OrderBy(Function(x) x.Prop1).ThenBy(Function(x) x.Prop2)

      

Your example:



Dim classCodeDetails As List(Of ClassCodeDetail) = _
   db.ClassCodeHeaders.Single(Function(cch) cch.CLCH_ID = classCodeHeaderId).ClassCodeDetails _
  .OrderBy(Function(c1) c1.Make.MAKE_English) _
  .ThenBy(Function(c1) c1.Make.MODL_English) _
  .ToList()

      

In fact, this is the correct way to do it (you seem to be using LINQ to SQL), as it will use ORDER BY

in the generated SQL statement to sort the data instead of manually sorting on the client.

+2


a source







All Articles