How Order by Case in LINQ
问题 I have this answer Entity framework OrderBy "CASE WHEN" but this only handle two options var p = ctx.People.OrderBy(p => (p.IsQualityNetwork == 1 || p.IsEmployee == 1) ? 0 : 1) .ThenBy(p => p.Name); I have a text field and want rows appear on an specific order. In sql I would do: ORDER BY CASE when name = "ca" then 1 when name = "po" then 2 when name = "pe" then 3 when name = "ps" then 4 when name = "st" then 5 when name = "mu" then 6 END 回答1: How about creating a map of your sort order? var