Order by collection count using ICriteria & NHibernate

余生颓废 提交于 2019-11-30 09:51:48

问题


Using the standard NHibernate example of Cats and Kittens, how would I use ICriteria to sort Cats based on Kitten count? For example, I want to do something like:

ICriteria crit = Session.CreateCriteria(typeof(Cat));
return crit.Order(Order.Asc("**Kittens.Count**"));

Anyone know how to achieve this?


回答1:


In HQL you can do it like this:

select cat
from Eg.Cat cat
join cat.Kittens kitten
group by cat
order by count(kitten) asc



回答2:


See http://forum.hibernate.org/viewtopic.php?p=2401219

It's Java Hibernate but almost the same thing (Projection, AddOrder)



来源:https://stackoverflow.com/questions/604572/order-by-collection-count-using-icriteria-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!