gpt4 book ai didi

c# - 多个 Orderby 和 Sort

转载 作者:太空狗 更新时间:2023-10-30 00:43:22 24 4
gpt4 key购买 nike

我有 2 个类:

 Employee
EmployeeDetails

我想要一个列表,首先对 Employee 进行排序,然后对其进行排序,然后对 EmployeeDetails 进行排序,然后对其进行排序。

我在想这样的事情:

var result = _db.Employee
.OrderBy( e => e.EmpName )
.Sort('DepartmentId') // using the diff property
.ThenBy( ed => ed.EmpAddress )
.Sort('PostCode'); // using the diff property

我需要先从 Employee 按 EmpName 排序,然后从那些我想按 EmpAddress 排序的结果集中对其进行排序,然后对其进行排序,然后返回结果集。

这可能吗?不使用 Lambdas 可以完成吗?是其他方法吗?

最佳答案

下面的代码是您要找的吗?

var result = _db.Employee
.OrderBy(e => e.EmpName)
.ThenBy(e => e.DeptartmentId)
.ThenBy(e => e.EmpAddresss)
.ThenBy(e => e.PostCode);

关于c# - 多个 Orderby 和 Sort,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11397601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com