Linq to NHibernate and Group By

后端 未结 1 555
野性不改
野性不改 2021-01-25 19:44

I\'m using the current Linq provider for NHibernate (version 2.1).

I have two entities: VideoGame and GameDeveloper, with a many-to-one relationship between them. I\'m t

相关标签:
1条回答
  • 2021-01-25 20:13

    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()};
    
    0 讨论(0)
提交回复
热议问题