如何在LINQ lambda中订购父类的基础子集 [英] How do I order an underlying child collection of a parent class in LINQ lambda

查看:112
本文介绍了如何在LINQ lambda中订购父类的基础子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

_ctx.DataContext.Set<ParentClass>().Include("ChildCollection").OrderBy(...)

每当我在OrderBy子句中放置一个Lambda表达式,我无法访问关于ChildCollection属性的属性,我希望底层的子集合被排序。我不想让任何特定的列排序父类。

Everytime I put a Lambda expression in the OrderBy clause I can't get access to the properties off the ChildCollection property that I want the underlying child collection to be ordered by. I don't want the parent class ordered by any specific column.

如何使用LINQ / Lambda表达式实现这一点?似乎应该真的很容易!

How do I achieve this using LINQ/Lambda expression? Seems like it should be really easy!

推荐答案

渴望加载不能订购导航属性。你必须使用这样的东西:

Eager loading is not able to order navigation properties. You must use something like this:

var query = _ctx.DataContext
                .Set<ParentClass>()
                .Select(p => new 
                   {
                      Parent = p,
                      Childs = p.ChildCollection.OrderBy(c => c.Something)
                   });

这篇关于如何在LINQ lambda中订购父类的基础子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆