I am trying to create query which orders by child collection’s property. It is quite easy in SQL:
Select Table1.*
From Table1
Inner join Table2 on Table1.Id = Table2.Table1Id
OrderBy Table1.Column1, Table2.Column1
Here is how I did it in NHibernate 2 and it worked fine:
var result = Session.Linq<Table1>()
.OrderBy(x => x.Column1)
.ThenBy(x => x.Table2.FirstOrDefault().Column1);
After migrating to NHibernate 3 this doesn’t work anymore. It throws NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Antlr.Runtime.NoViableAltException.
I am using NHibernate 3.1. Are there other solutions for such query?
The two queries aren’t the same. The LINQ version (roughly) equates to:
EDIT
If you want to replicate the original sql you might want something like: