How can I use linq to sort by multiple fields?

前端 未结 6 1515
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-29 05:21

I\'m creating a mock data source that I want to be able to pass in a list of SortExpressions on.

public SortExpression(string name, SortDirection direction)
         


        
6条回答
  •  半阙折子戏
    2020-12-29 06:00

    The query is not mutable, so OrderBy returns a new object. You need to make the same call, but add "query =" to the beginning.

    query = query.OrderBy(item => item.GetType().GetProperty(sortExpressions[i].Name));
    

提交回复
热议问题