我有以下 LinQ 查询 var CGTABLE = (from cg in DbContext.CGTABLE join tcg in DbContext.TCGTABLE on new { cg.CGroupId } equals new { tcg.CGroupId } where tcg.TId == TId select new { CGroupId = cg.CGroupId, CGroupCode = cg.CGroupCode, Description = cg.Description, C = cg.C, DisplayOrder = cg.DisplayOrder }).ToList(); CGTABLE = CGTABLE.OrderBy(g => g.DisplayOrder).ThenBy(g => g.C.OrderBy(c => c.CCode)).ToList();运行良好,但它没有通过使用 ThenBy 进行第二次排序ThenBy(g => g.C.OrderBy(c => c.CCode)我错过了什么?Sample data for better understanding.Data in Tables2 1 2 4 31 4 5 2 13 3 1Should output after both outer and inner list ordered by1 1 2 3 42 1 2 4 53 1 3But Currently it is showing1 4 5 2 12 1 2 4 33 3 1
1 回答
阿波罗的战车
TA贡献1862条经验 获得超6个赞
您不想订购主列表,我想您正在寻找一种在外部列表中订购内部列表的方法。所以下面的代码会为你做:
var CGTABLE = (
from cg in DbContext.CGTABLE
join tcg in DbContext.TCGTABLE on new { cg.CGroupId } equals new { tcg.CGroupId }
where tcg.TId == TId
select new {
CGroupId = cg.CGroupId,
CGroupCode = cg.CGroupCode,
Description = cg.Description,
C = cg.C.OrderBy(x => x.CCode),
DisplayOrder = cg.DisplayOrder
}).ToList();
CGTABLE = CGTABLE.OrderBy(g => g.DisplayOrder).ToList();
- 1 回答
- 0 关注
- 196 浏览
添加回答
举报
0/150
提交
取消