Search code examples
nhibernatequeryovercross-join

Crossjoin using QueryOver


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

Solution

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