本文介绍了使用QueryOver进行交叉联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How could I replace the HQL query below using QueryOver API?

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();

推荐答案

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

I don't believe there's a way to do this in QueryOver, since both JoinAlias and JoinQueryOver require an expression describing a path to the related entity.

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

However, this is easy to accomplish in 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:

With NH 3.2, here's the SQL I get:

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 */

这篇关于使用QueryOver进行交叉联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 13:28