我有这个orderby问题,我需要根据列值排序linq表达式。代码是这样的。
JsonResult resultCombined = new JsonResult();
List<String> preferences = new List<String> { "E", "M", "H"};
var listCounties = sc.Districts(null, null);
var listSchools = sc.Schools(s => s.YEAR == "2015");
var result = listCounties.Join(listSchools,
i1 => i1.LEA,
i2 => i2.LEA,
(i1, i2) => new { i1, i2 })
.OrderBy(i3=>i3.i2.SCHOOLCODE)
.ThenBy(i3 => i3.i2.SCHOOLNAME);
resultCombined.Data = result;
return resultCombined;
这里我的问题是我需要根据优先顺序订购结果,其中SCHOOLCODE包含首选项。只需订购SCHOOLCODE就不会给我订单。请帮我一些建议或代码。
谢谢
答案 0 :(得分:0)
尝试先过滤记录,然后应用排序。
var result = listCounties.Join(listSchools,
i1 => i1.LEA,
i2 => i2.LEA,
(i1, i2) => new { i1, i2 })
.Where(i3=>i3.i2.SCHOOLCODE.Contains(preference)
.OrderBy(i3=>i3.i2.SCHOOLCODE)
.ThenBy(i3 => i3.i2.SCHOOLNAME);