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.
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)
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With