LINQ multiple order by

后端 未结 3 834
既然无缘
既然无缘 2020-12-21 05:09

I have created a function that has the follwing parameter:

List>> orderBy = null

T

3条回答
  •  攒了一身酷
    2020-12-21 05:36

    Two problems; firstly, ThanBy should be ThenBy; secondly, ThenBy is only available on the generic type, IOrderedQueryable.

    So change to:

            IOrderedQueryable temp = null;
            foreach (Expression> func in orderBy) {
                if (temp == null) {
                    temp = catalogProducts.OrderBy(func);
                } else {
                    temp = temp.ThenBy(func);
                }
            }
    

    and you should be sorted.

提交回复
热议问题