如何使用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();
答案 0 :(得分:3)
我不相信在QueryOver中有一种方法可以做到这一点,因为JoinAlias
和JoinQueryOver
都需要一个描述相关实体路径的表达式。
但是,在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 */