Tamaño de HQL usando QueryOver sin subconsulta

Hope that someone can answer this.

I know that I can do the following using hql (pseudo code below)

var hql = "from objectA l where size(l.ChildCollection) > 0";

var data = Session.CreateQuery(hql)
            .List<objectA>();

Is there a wondering if you could do something similar using QueryOver. Without resorting to using a sub query.I have a session filter on ChildCollection.

Desafortunadamente,

var query = QueryOver.Of<ObjectA>()
.WhereRestrictionOn(x => x.ChildCollection).IsNotEmpty();

Produces,

WHERE
    exists(
        select
            1 
        from
            [ChildCollection] 
        where
            this_.Id=ObjectA_Id
    );

Where as the Hql produces,

where
(
   select
       count(childcollection1_.ObjectA_Id) 
   from
       [ChildCollection] childcollection1_ 
    where
       objectA0_.Id=childcollection1_.ObjectA_Id 
       and childcollection1_.DTCreated between @p0 and @p1
    )>0

¡Salud

Tanzy

preguntado el 30 de enero de 12 a las 20:01

1 Respuestas

var query = QueryOver.Of<ObjectA>().WhereRestrictionOn(x => x.ChildCollection).IsNotEmpty();

Both queries will generate similar sql:

SELECT this_.Id
FROM   [ObjectA] this_
WHERE  exists(select 1 from [ChildObjectB] where this_.Id = [key])

¿Es esto lo que estabas tratando de lograr?

Respondido el 31 de enero de 12 a las 03:01

I've edited question as can't fit the information in the comment - Tanzy

Can you explain why are you trying to generate exactamente the same sql? The execution plan in sql-server will be identical for both queries - MonkeyCoder

The ChildCollection has a filter assigned to it, so when using size(ChildCollection) in the HQL it includes the session filter that has been set on its limitation. However, using the QueryOver IsNotEmpty does not use this session filter. - Tanzy

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.