Linq to NHibernate and Group By

老子叫甜甜 提交于 2019-12-02 06:11:18

How about

from v in session.Linq<VideoGame>()
group by v.Developer into developerGroup
select new {key = developerGroup.Key, count = developerGroup.Count()}

Seems like group by is broken in the 2.1 NHibernate LINQ provider. A while ago Steve Strong blogged that group by is in the trunk so if you are feeling adventurous enough and not willing to wait on 3.0 then that could be an option.

Or you could use a brute force solution something like this

from v in (from vg in session.Linq<VideoGame>() select vg).ToList()
group by v.Developer into developerGroup
select new {developerGroup.Key.Name, Count = developerGroup.Count()};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!