相关疑难解决方法(0)

LINQ OrderBy Name ThenBy ChildrenCollection.Name

在LINQ中有没有办法做一个OrderBy,然后用ThenBy做一个ThenBy,使用父对象的子进行二次排序?

_repository.GetActiveDepartmentGroupsWithDepartments().OrderBy(c => c.DepartmentGroupName).ThenBy(c => c.Departments.OrderBy(d => d.DepartmentName))
Run Code Online (Sandbox Code Playgroud)

在上面的例子中,c.Departments是一个EntityCollection.

顺便说一句:当我尝试上面的内容然后对其执行ToList()时,我收到此错误:

DbSortClause expressions must have a type that is order comparable.
Parameter name: key
Run Code Online (Sandbox Code Playgroud)

在此先感谢任何帮助或指导.

c# linq linq-to-entities entity-framework

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

entity-framework ×1

linq ×1

linq-to-entities ×1