Order column by a separate `List` variable

前端 未结 2 1123
执笔经年
执笔经年 2020-12-12 06:16

I need to sort the results of an entity framework query by the index of elements in another list.

I tried the suggestion found elsewhere, like

.Then         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 06:47

    this should do the trick:

    private IEnumerable PopulateQuery(string selectedCampus)
    {
        var list = new List {"Fall","Mid","Spring"};
        return _db.MiaLog1A.Where(m => m.Campus == selectedCampus)
            .AsEnumerable()
            .OrderBy(m => m.StudentName)
            .ThenBy(m=> list.IndexOf(m.Term));
    }
    

提交回复
热议问题