Hello,

I'm trying to use linq to generate this sql:

select u.Id, SUM(i.Amount)
from dbo.UserInfo u
join dbo.Invitation i on u.Id = i.UserInfo_id
group by u.Id

These are my two attempts:

var users = session.Query<UserInfo>();
var invitations = session.Query<Invitation>();


1)

var res2 = from u in users
        join i in invitations on u.Id equals i.UserInfo.Id
        select new {u.Id, i} into o
        group o by o.Id into v
        select new {v.Key, amount = v.Sum(x => x.i.Amount)};


2)
var res = users
        .Join(invitations, u => u.Id, i => i.UserInfo.Id, (u, i) => new { u, i 
})
        .Select(o => new { o.u.Id, o.i.Amount })
        //.ToList()
        .GroupBy(
                o => o.Id,
                (id, group) => new { id, amount = group.Sum(g => g.Amount) }
                );


(2) Works ok if  I uncomment ".ToList()", but that's not what I want.

What is the correct way to invoke GroupBy?

Regards,

  Juan Pablo

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