c# – 如何使用Entity Framework包含已排序的导航属性

前端之家收集整理的这篇文章主要介绍了c# – 如何使用Entity Framework包含已排序的导航属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个实体A,里面有B的集合.我用_entity.A.Include(a => a.B)加载它们

现在我希望将B放入A中,按自定义OrderBy排序.我试过_entity.A.Include(a => a.B.OrderBy(o => o.Version)但我得到了:

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.

有关如何实现这一目标的任何想法?

谢谢.

版本是整数.

解决方法

我想在这种情况下你可以尝试:
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)
        });

猜你在找的C#相关文章