Order by relation count in NHibernate

烂漫一生 提交于 2019-12-01 14:58:37
var loadedUser = session.Query<User>()
    .Select(u => new { u, u.Books.Count })
    .ToList()
    .OrderBy(anonym => anonym.Count)
    .Select(anonym => anonym.u);

or using HQL

select user
from User as user 
    left join user.Books as books
group by user
order by count(books)
mathieu

See : Order by collection count using ICriteria & NHibernate

select u
from User u
join u.Books b
group by u
order by count(b) asc

Or using LINQ :

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