如何排序包含导航属性与实体框架实体、框架、属性

由网友(你瞎啊撞我心上了#)分享简介:我有 A 与 B的里面集合的实体。我加载它们与 _entity.A.Include(A => AB) I have an entity A with a collection of B inside. I load them with a _entity.A.Include(a => a.B)现在我想有B的为...

我有 A B的里面集合的实体。我加载它们与 _entity.A.Include(A => AB)

I have an entity A with a collection of B inside. I load them with a _entity.A.Include(a => a.B)

现在我想有B的为A排序自定义排序依据。我试过 _entity.A.Include(A => aBOrderBy(O => o.Version)但我得到一个:

Now I want to have the B's into A sorted by a custom OrderBy. I tried _entity.A.Include(a => a.B.OrderBy(o => o.Version) but I get a :

包括路径EX pression必须引用的类型定义的导航属性。用虚线路径参考导航属性和集合导航属性选择运营商。

The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.

这是如何做到这一点任何想法?

Any ideas on how to accomplish this?

感谢。

版是整数

推荐答案

我觉得在这种情况下,你可以试试:

I think in this case you can try:

var list = _entity.A.Include("B").ToList();
list.ForEach(m => m.B = m.B.OrderBy(o => o.Version));

_entity.A.Include("B").Select(m => new A {
        //some props,
        B = m.B.OrderBy(o => o.Version)
        });
阅读全文

相关推荐

最新文章