8

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

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 :

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?

Thanks.

Version is an integer.

Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207

1 Answers1

4

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));

or:

_entity.A.Include("B").Select(m => new A {
        //some props,
        B = m.B.OrderBy(o => o.Version)
        });
Mateusz Rogulski
  • 7,357
  • 7
  • 44
  • 62