Reputation: 825
I am getting a MismatchedTreeNodeException throw with the simple query below using NHibernate 3.2.0.4000. I am assuming it is a bug and if so does anyone know of a work around?
var result = session.Query<File>()
.OrderBy(x => x.Author)
.GroupBy(file => file.Author)
.Select(author => new FileAuthor(author.Key, author.Count()))
.ToList();
Upvotes: 1
Views: 1096
Reputation: 2694
I have played around with your example and query in this form works fine:
var result = session.Query<File>()
.GroupBy(file => file.Author)
.Select(author => new
{
Key = author.Key.AuthorId,
Count = author.Count()
})
.ToList();
Apparently, when you group by entity, it is possible only to project its ID and aggregations. It seems that sorting needs to be done on the client.
Used mappings:
<class name="Author" table="authors">
<id name="AuthorId" column="author_id" />
<property name="AuthorName" column="author_name" />
<bag name="Files">
<key>
<column name="author_id" />
</key>
<one-to-many class="File"/>
</bag>
</class>
<class name="File" table="files">
<id name="FileId" column="file_id" />
<property name="FileName" column="file_name" />
<many-to-one name="Author" class="Author">
<column name="author_id" />
</many-to-one>
</class>
Upvotes: 1