Crossjoin using QueryOver

老子叫甜甜 提交于 2019-11-30 19:32:41

问题


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

回答1:


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.

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

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


来源:https://stackoverflow.com/questions/9643934/crossjoin-using-queryover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!