假设您使用composite-element映射UserBook类:
var top10Books = session .CreateQuery(@"select b.Book from User u join fetch u.Books b where b.Status = :status") .SetParameter("status", "Read") .SetMaxResults(10) .SetResultTransformer(CriteriaSpecification.DistinctRootEntity) .List();
这是完整源代码的链接.
编辑:
我看到你需要阅读一本书的次数.这是查询:
var top = session .CreateQuery(@"select b.Book, count(b.Book.Id) from User u join fetch u.Books b where b.Status = :status group by b.Book") .SetParameter("status", "Read") .SetMaxResults(10) .List