使用QueryOver交叉连接

时间:2012-03-10 04:28:27

标签: nhibernate queryover cross-join

如何使用QueryOver API替换下面的HQL查询?

var sql = "from Role r, Action a where r.Active = :active and a.Active = :active";
var result = manager.Session.GetISession().CreateQuery(sql)
            .SetBoolean("active", true).List();

1 个答案:

答案 0 :(得分:3)

不相信在QueryOver中有一种方法可以做到这一点,因为JoinAliasJoinQueryOver都需要一个描述相关实体路径的表达式。

但是,在LINQ-to-NHibernate中很容易实现:

var result = 
    (from role in manager.Session.GetISession().Query<Role>()
    from action in manager.Session.GetISession().Query<Action>()
    where role.Active == true && action.Active == true).ToList();

使用NH 3.2,这是我得到的SQL:

select role0_.Id    as col_0_0_,
       action1_.Id as col_1_0_
from   [Role] role0_,
       [Action] action1_
where  role0_.IsActive = 1 /* @p0 */
       and action1_.IsActive = 1 /* @p1 */