我使用NHibernate 3.2.0.4000通过下面的简单查询获得了MismatchedTreeNodeException抛出。我假设这是一个错误,如果有的话,有人知道一个工作吗?
var result = session.Query<File>()
.OrderBy(x => x.Author)
.GroupBy(file => file.Author)
.Select(author => new FileAuthor(author.Key, author.Count()))
.ToList();
答案 0 :(得分:0)
我已经玩过您的示例,并且此表单中的查询工作正常:
var result = session.Query<File>()
.GroupBy(file => file.Author)
.Select(author => new
{
Key = author.Key.AuthorId,
Count = author.Count()
})
.ToList();
显然,当您按实体分组时,只能投影其ID和聚合。似乎需要在客户端上进行排序。
使用过的映射:
<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>