0

有人可以帮我把这个查询翻译成 NHibernate 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
4

1 回答 1

0

Hibernate does not allow subqueries in the from clause. You can rewrite this using in instead:

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
              )
于 2013-08-25T13:22:44.867 回答