Domanda

Come posso sostituire la query HQL qui sotto usando l'API di query?

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

È stato utile?

Soluzione

I Do not Believe C'è un modo per farlo in queryover, poiché sia generacolodicetagcode e JoinAlias richiedono un'espressione che descrive un percorso all'entità correlata.

Tuttavia, questo è facile da realizzare in Linq-to-Nibernate:

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

Con NH 3.2, ecco il SQL I ottengo:

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top