Nhibernate many to many criteria query with subselect
- by Max
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