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
.ThenBy(m=>list.IndexOf(m.Term))
but I get an HTTP 500 error, so I'm wondering if I'm missing something. When debugging, I get this inner exception.
LINQ to Entities does not recognize the method 'Int32
IndexOf(System.String)' method, and this method cannot be translated
into a store expression.
In particular, I'm thinking of this scenario.
private IEnumerable<MiaLog1A> PopulateQuery(string selectedCampus)
{
var list = new List<string> {"No Longer Alphabetical","Fall","Mid","Spring"};
return _db.MiaLog1A.Where(m => m.Campus == selectedCampus)
.OrderBy(m => m.StudentName)
.ThenBy(m=>m.Term)
/* I would like to sort "Term" by the
* order of "list".
*/
.AsEnumerable();
}
Is there a way I could sort in this manner, or am I restricted to ordering by a dictionary or creating a join?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…