加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 05:36:35 所属栏目:百科 来源:网络整理
导读:我有一个实体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
我有一个实体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)
        });

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读