我有以下数据结构:
+-----+ 1:N +------------+ M:N +---------+
|Book | ---> |BookVersion | ---> |Category |
+-----+ +------------+ +---------+
Book有许多版本,每个版本都属于许多类别(简化场景)。我试图使用Futures获取带有类别的BookVersion(根据https://stackoverflow.com/a/21627753) 并试图避免笛卡尔积:
Book bookAlias = null;
BookVersion bookVersionAlias = null;
BookType bookTypeAlias = null;
Category categoryAlias = null;
using (var session = GetSession())
{
var bookVersions =
session.QueryOver(() => bookVersionAlias)
.JoinAlias(() => bookVersionAlias.Categories, () => categoryAlias, JoinType.InnerJoin)
.JoinAlias(() => bookVersionAlias.Book, () => bookAlias, JoinType.InnerJoin)
.Where(() => categoryAlias.Type == BOOK_TYPE && bookVersionAlias.Id == bookAlias.LastVersion.Id)
.Future<BookVersion>();
var categories = session.QueryOver(() => categoryAlias)
.Where(x => x.Type == BOOK_TYPE)
.Future<Category>();
return bookVersions.ToList();
}
结果BookVersion列表不包含类别。
如何在NHibernate 4.0中使用QueryOver获取多对多?