I didn't find a proper solution yet. My current workaround consists of 2 queries, the first to retrieve the key as Id together with the aggregate values and a second query using a Contains clause with the IDs list... afterwards I remix the two lists together to match by IDs.
I thought about diving into the code and try to see if I'm up to the task of patching up the Linq provider but I didn't have the time for it yet. It'll be a first time for me on the NH codebase and I don't even know where to start yet. On Jan 10, 5:01 pm, James Crowley <[email protected]> wrote: > I've hit the same issue - did you find a solution? If you find a way while > still using LINQ (rather than having to bring in direct NH dependencies on > HQL/QueryOver) please do post back here! > > Not sure if there's a JIRA bug for this stuff, but would seem like a common > requirement? > > Thanks! > > James > > On 6 January 2011 13:02, Variant <[email protected]> wrote: > > > > > > > > > I am trying to perform a group by Linq query with NH3. Knowing the > > underling SQL difficulties I know it's not possible but Ideally I > > would like to do the group by an entity and have it retrieved in it's > > entirety. Something like: > > > var list = from proposals in Session.Query<Proposal>() > > group proposals by proposals.Job > > into jobGrouping > > select new { > > Job = jobGrouping.Key, > > TotalProposals = jobGrouping.Count() > > }; > > This generates an illegal SQL query as it tries to retrieve the whole > > Job entity but group only by its Id. > > > I have tried grouping by a composite field: > > > var list = from proposals in Session.Query<Proposal>() > > group proposals by new { proposals.Job.Name, > > proposals.Job.Status} > > into jobGrouping > > select new { > > Job = jobGrouping.Key.Name, > > Status = jobGrouping.Key.Status, > > TotalProposals = jobGrouping.Count() > > }; > > But whenever I try this I get an Exception when NHibernate tryes to > > build an expression tree: > > > An item with the same key has already been added. > > > Anyone knows if there is any way to accomplish that with NHibernate ? > > > Thanks, Ilan > > > -- > > You received this message because you are subscribed to the Google Groups > > "nhusers" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<nhusers%[email protected] > > > > > . > > For more options, visit this group at > >http://groups.google.com/group/nhusers?hl=en. -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
