如何对多列进行排序?我尝试使用这个表达式:
if (name != null)
{
if (name.Equals(SortEnum.ASC))
{
employees = employees.OrderBy(e => e.Name);
}
else if (name.Equals(SortEnum.DESC))
{
employees = employees.OrderByDescending(e => e.Name);
}
}
if (surname != null)
{
if (surname.Equals(SortEnum.ASC))
{
employees = employees.OrderBy(e => e.Surname);
}
else if (surname.Equals(SortEnum.DESC))
{
employees = employees.OrderByDescending(e => e.Surname);
}
}
但只有最后一列被排序。我在某个地方看到了 method ThenBy()
,但我没有。请帮忙。