1

This question as an extension from this question: Sorting Dynamic LINQ By Collection Property

I have a query that can be strongly expressed like this (works):

qry.OrderBy(x => x.Locations.Where(l => l.SequenceNo == 1).Min(l => l.Location.Name))

I've tried expressing this like this (does not work):

qry.OrderBy("Locations.Where(SequenceNo=1).Min(Location.Name)");

This is not recognized however.

I cannot find any official documentation for Dynamic Linq either.

Is this scenario possible/supported with Dynamic Linq?

EDIT: The example was incomplete as it did not show the complete sample. I've decided to let the code remain and update below instead (neither statements work).

qry.OrderBy(x => x.Locations.Where(l => l.SequenceNo == 1).Min(l => l.Location.Name)).ThenBy(v=>v.ID);
qry.OrderBy("Locations.Where(SequenceNo=1).Min(Location.Name), ID");

I need to sort on the ID as well to have an unique result set.

I guess the issue now isn't specific to Dynamic Linq but rather how the expressions are linked.

Community
  • 1
  • 1
Vincent
  • 1,119
  • 11
  • 25
  • Can you try without `Where` clause? I cannot find some documentation now, but `qry.OrderBy("Locations.Min(Location.Name)")` should absolutly work. – Razvan Dumitru Nov 08 '16 at 14:29
  • I cannot. The Locations contain several records and in this particular example I should only sort on the one with SequenceNo == 1 – Vincent Nov 08 '16 at 14:31
  • I understand that. What i'm trying to say is that most probably the `Where` clause is causing problems for `Dynamic Linq` in your scenario and that probably you won't be able to use a `Where` clause in there. – Razvan Dumitru Nov 08 '16 at 14:34
  • 1
    That would be an identical example of http://stackoverflow.com/questions/35496303/sorting-dynamic-linq-by-collection-property which I've applied to other sections of the project, so that works. – Vincent Nov 08 '16 at 14:36
  • 2
    It works in my test environment (Assembly System.Linq.Dynamic, Version=1.0.5840.25917). – Ivan Stoev Nov 08 '16 at 14:38
  • You are correct, my example was incomplete - for this I am sorry. I've updated the description. – Vincent Nov 08 '16 at 14:53
  • Hmm, that works too (both static and dynamic). What exactly doesn't work - are you getting an exception or ? – Ivan Stoev Nov 08 '16 at 14:58
  • Yeah, NHibernate.Hql.Ast.ANTLR.QuerySyntaxException. A recognition error occurred. Are you using in-memory data, entity framework or? – Vincent Nov 09 '16 at 07:08
  • Latest Entity Framework 6.1.3 – Ivan Stoev Nov 09 '16 at 12:49

0 Answers0