How do I order an underlying child collection of a

2019-08-20 13:46发布

For example:

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

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.

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

1条回答
Lonely孤独者°
2楼-- · 2019-08-20 14:10

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)
                   });
查看更多
登录 后发表回答