I am using System.Linq.Dynamic and have the following simplified structure (model):
Parent -> Children (Collection of type Child)
Child has property SortingOrder
I would like retrieve list of Parents include Children and order by Sorting Order.
I can do that with LINQ / C# code
Parents.OrderBy(x=>x.Children.OrderBy(z=>z.SortingOrder).Select(z=>z.SortingOrder).FirstOrDefault())
It works fine with EF (6.0) but problem is with all dynamic examples using string I cannot find solution to create the same expressions from string. So ultimately it should be sorted like this
Parents.Include("Children").OrderBy("Children.SortingOrder")
Obviously Children as collection does not have SortingOrder and therefore all examples fails.
Please advice, could not find solution for hours. I think solution would be in creating that lambda expression (x=>x.Children.OrderBy(z=>z.SortingOrder).Select(z=>z.SortingOrder).FirstOrDefault())
dynamically but not sure how to do that, or any other help greatly appreciated.
I am sure it's doable as it's working as compiled strongly typed expression.
Examples of code researched: