级联IsLike上的nhibernate查询覆盖子查询联接

级联IsLike上的nhibernate查询覆盖子查询联接,nhibernate,subquery,concatenation,queryover,sql-like,Nhibernate,Subquery,Concatenation,Queryover,Sql Like,我是nHibernate和QueryOver的新手,在C#中重写一些sql到QueryOver时遇到困难。有人能帮我吗?我的特殊问题是,我通过一个包含IsLike和一个串联值的析取来连接一个子查询,但我找不到正确的方法 以下是所涉及数据库表的简化版本和一些示例数据: create table Rating ( id INT, description VARCHAR(20), value INT ); create table Category (

我是nHibernate和QueryOver的新手,在C#中重写一些sql到QueryOver时遇到困难。有人能帮我吗?我的特殊问题是,我通过一个包含IsLike和一个串联值的析取来连接一个子查询,但我找不到正确的方法

以下是所涉及数据库表的简化版本和一些示例数据:

create table Rating (
  id          INT,
  description VARCHAR(20),
  value       INT
);

create table Category (
  id            INT,
  categoryName  VARCHAR(20),
  parentId      INT,
  path          VARCHAR(100)
);

create table Movie (
  id              INT,
  categoryId      INT,
  title           VARCHAR(50),
  description     VARCHAR(500),
  editorsRatingId INT,
  usersRatingId   INT
);

insert into Rating values (34, 'Bad', 1);
insert into Rating values (35, 'Good', 5); 
insert into Rating values (36, 'Excellent', 9);

insert into Category values (1, 'Sports', null, 'SPO');
insert into Category values (2, 'Baseball', 1, 'SPO/BAB');
insert into Category values (3, 'Motor', 1, 'SPO/MOT');
insert into Category values (4, 'Documentary', null, 'DOC');
insert into Category values (5, 'Nature', 4, 'DOC/NAT');
insert into Category values (6, 'Political', 4, 'DOC/POL');
insert into Category values (7, 'Constructions', 4, 'DOC/CON');

insert into Movie values (1, 3, 'A motor sports title', 'A motor sports description', 35, 34);
insert into Movie values (2, 2, 'A baseball title', 'A baseball description', 35, 36);
insert into Movie values (3, 5, 'A nature documentary', 'A nature documentary description', 36, 35);
insert into Movie values (4, 7, 'A construction documentary', 'A construction documentary description', 35, 36);
下面是我想用QueryOver构建的sql:

--Try running this with 0, 1 and 4 as :parentId
select c1.id, c1.categoryName, max(subQuery.eRating) as eRating1, max(subQuery.uRating) as uRating1
from Category c1
  join (
    select c.path, max(editorsRating.value) as eRating, max(usersRating.value) as uRating
    from Category c
      join Movie m on (m.categoryId = c.id)
      join Rating editorsRating on (editorsRating.id = m.editorsRatingId)
      join Rating usersRating on (usersRating.id = m.usersRatingId)
    group by c.path
    ) as subQuery on (subQuery.path = c1.path or subQuery.path like concat(c1.path,'/%'))
where coalesce(c1.parentId, 0) = :parentId
group by c1.id, c1.categoryName 
评级值应始终返回所有级别上每个类别项的子类别中的聚合最大值

如果有人能给我一个提示,特别是关于连接值的子查询连接部分,我将不胜感激