需要帮助将此查询转换为NHibernate Criteria

时间:2013-08-25 13:20:15

标签: sql nhibernate orm

有人可以帮我翻译这个查询到NHibernate Criteria吗?或者Criteria不适合这个吗?

查询:

SELECT b.*
 FROM Bookmarks b
 JOIN (SELECT tg.BookmarkId
        FROM TagsBookmarks tg
        JOIN Tags t ON t.id = tg.TagId
        WHERE t.Title IN ('c#','tutorials')
      GROUP BY tg.BookmarkId
        HAVING COUNT(DISTINCT t.Title) = 2) x ON x.BookmarkId = b.Id

1 个答案:

答案 0 :(得分:0)

Hibernate不允许from子句中的子查询。您可以使用in重写此内容:

SELECT b.*
FROM Bookmarks b
where b.id in (SELECT tg.BookmarkId
               FROM TagsBookmarks tg JOIN
                    Tags t
                    ON t.id = tg.TagId
               WHERE t.Title IN ('c#','tutorials')
               GROUP BY tg.BookmarkId
               HAVING COUNT(DISTINCT t.Title) = 2
              )