I am trying this as a Linq query:

            var query = from entry in entryquery
                        group entry by entry.Account into list
                        select new AccountTake
                        {
                            Account = list.Key,
                            CreditAmount = list.Sum(p => p.Amount),
                            DebitAmount = list.Sum(p => p.Amount)
                        };

And this is the resulting SQL

SELECT sum(this_.Amount) as y0_,
       sum(this_.Amount) as y1_
FROM   Entries this_

Seems to be ignoring group by.  Obviously this returns an exception as it
can't map that to AccountTake.

Chris

On Wed, Jun 3, 2009 at 3:53 PM, Fabio Maulo <[email protected]> wrote:

> Not with anonymous type but with a real Type or a IList<object[]>
>
> 1)select e.Key, sum(e.Amount) from Entry e group by e.Key
> 2)select new YourStatisticEntry(e.Key, sum(e.Amount)) from Entry e group by
> e.Key
> 3) using 1 with a results trasformer to transform each result or the
> entirely IList.
>
> 2009/5/28 Chris Nicola <[email protected]>
>
> I was wondering if it is possible to do simple sums and groupings with
>> Linq2Nhibernate without returning the entire result set first using
>> .ToList();
>>
>> My scenario:
>>
>> I have a table of accounts, and for each and every account I would like to
>> get a sum of transactions from three different tables.  In SQL I would do
>> something like
>>
>> SELECT SUM(Amount), Account.id
>> FROM Entries
>> Group By Account.id
>>
>> In a Linq query I might try to return something like:
>>
>> from entry in session.Linq<Entry>()
>> group entry by entry.Account into list
>> select new
>> {
>>   Account = list.Key,
>>   Total = list.Sum(e => e.Amount)
>> };
>>
>> However that returns an error because nHibernate is expecting to return
>> entities of type <Entry> and not the anonymous type I just defined.
>>
>> Is there any way to get results like this?
>>
>> Thanks,
>> Chris
>>
>>
>>
>
>
> --
> Fabio Maulo
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to