When I use a group by, if I want to use an order by on group items subquery, the order by is ignored. Is this a bug? Should I write my query differently?

new MyEntity(session) { Text = "test 1", Text2 = "2" };
new MyEntity(session) { Text = "test 1", Text2 = "3" };
new MyEntity(session) { Text = "test 1", Text2 = "1" };
new MyEntity(session) { Text = "test 2", Text2 = "2" };
new MyEntity(session) { Text = "test 2", Text2 = "3" };
new MyEntity(session) { Text = "test 2", Text2 = "1" };

Query:

var query = from e in session.Query.All<MyEntity>()
            group e by e.Text into g
            select new { Key = g.Key, First = g.OrderBy(e => e.Text2).Select(e => e.Text2).FirstOrDefault() };

Result :

  • test 1, 2
  • test 2, 2

I was expecting :

  • test 1, 1
  • test 2, 1

asked Jan 26 '12 at 03:07

olorin's gravatar image

olorin
356818489

Hello olorin,

Thanks for submitting the case, right now we are in the process of fixing it. It is expected to be done shortly.

(Jan 26 '12 at 03:40) Dmitri Maximov Dmitri%20Maximov's gravatar image

One Answer:

Issue is fixed. Fix will be included in next minor updates for v4.3 and v4.4.

answered Jan 26 '12 at 11:33

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

1

Thank you!

(Jan 27 '12 at 03:02) olorin olorin's gravatar image
1

That was fast! Thank you

(Jan 27 '12 at 03:03) olorin olorin's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA