Nhibernate many to many criteria query with subselect

Posted by Max on Stack Overflow See other posts from Stack Overflow or by Max
Published on 2009-06-22T13:47:40Z Indexed on 2010/04/16 4:23 UTC
Read the original article Hit count: 458

Filed under:
|

I have a simple example of a blog: a Post table, a Tag table and a Post_Tag_MM lookup table linking the two tables.

I use this hql query in order to fetch all posts, that DONT have some tags:

            var result = session
                            .CreateQuery(@"
                                select p from Post p 
                                join p.Tags t 
                                where (select count(ti) from p.Tags ti where ti.Uid in (:uidList)) = 0
                            ")
                            .SetParameterList("uidList", uidList)
                            .SetResultTransformer(new DistinctRootEntityResultTransformer())
                            .List<Post>();

How can this many-to-many query and the subselect translated into a criteria query?

I dont quite understand the DetachedCriteria API yet and could not get it to return the right resultset.

Thank you very much in advance.

Regards,

Max

© Stack Overflow or respective owner

Related posts about c#

Related posts about nhibernate