Link to home
Start Free TrialLog in
Avatar of si2030
si2030

asked on

LINQ multiple column grouping

Hi Experts,

I am trying to build a statement  where I group on more than one column. I have looked on the web and found this site: http://ddkonline.blogspot.com/2008/04/linq-group-by-syntax-for-grouping-on.html

He supplies this statement in C#:

from f in FundUserRoles
group f by new {f.RoleId, f.UserName}
into myGroup
where myGroup.Count() > 0
select new { myGroup.Key.RoleId, myGroup.Key.UserName, FundCount = myGroup.Count()}

I then tried to make one similar but cannot do it in VB.NET

 Dim test = From ledger In db.ledgers _
                           Group By New {ledger.postingID, ledger.link_posting_id} Into mygroup() Select mygroup.postingId

Wondering if someone might show me the way..

Kind Regards

Simon
Avatar of bhmahler
bhmahler
Flag of United States of America image

you don't need all that to group on multiple columns, you just need to group by them

Dim test = From ledger in db.ledgers _
                 Group By ledger.postingID, ledger.link_posting_id _
                 Select ledger.postingID
ASKER CERTIFIED SOLUTION
Avatar of bhmahler
bhmahler
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of si2030
si2030

ASKER

I ended up working this out a different way however the answers above both address the question and thus work...