NHibernate ICriteria - order by child collection count? -


here simple example scenario -

a 'tag' has many 'questions'. when list of tags how order tags question count using criteria api?

i have done before haven't touched nh in 4 months , have forgotten... projections maybe? help!!!

thanks

sat down fresh pair of eyes , figured out... tags ordered propery on tags question collection (views).. made alot more sence in domain ordering count of children

    public ilist<tag> gettop(int numberoftags)     {         using (itransaction transaction = session.begintransaction())         {              detachedcriteria detachedcriteria = detachedcriteria.for<tag>()                     .createcriteria<tag>(x => x.questions)                     .addorder<question>(x => x.views, order.desc)                     .setmaxresults(numberoftags)                     .setprojection(projections.distinct(projections.id()));              ilist<tag> tags = session.createcriteria<tag>()                 .setfetchmode<tag>(x => x.questions,fetchmode.join)                 .add(lambdasubquery.property<tag>(x => x.id).in(detachedcriteria))                 .setresulttransformer(new distinctrootentityresulttransformer())                 .list<tag>();              transaction.commit();             return tags;         }     } 

Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -