CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Linq2Object group by query

249 Views
Copy Code Show/Hide Line Numbers
   1:  public IResult GetResultTree()
   2:  {
   3:      return new WebServiceResult<CampaignSessionBeanClient, GetCampaignTreeResultCompletedEventArgs>(x => x.GetCampaignTreeResultAsync(GetCampaignFilter()), x =>
   4:      {
   5:          var propsals = new ProposalMapper().MapMany(x.Result);
   6:          var Agencies = from agc in propsals
   7:                         group agc by agc.Agency.OrgOrgRoleId into agcGroup 
   8:                         select new
   9:                         {
  10:                             OrgOrgRoleIdAgc = agcGroup.Key,
  11:                             Advertisers = from adv in agcGroup
  12:                                           group adv by adv.Advertiser.OrgOrgRoleId into advGroup 
  13:                                           select new
  14:                                           {
  15:                                               OrgOrgRoleIdAdv = advGroup.Key,
  16:                                               Products = from prd in advGroup
  17:                                                          group prd by prd.Product.ProductId into prdGroup
  18:                                                          select new
  19:                                                          {
  20:                                                              ProductId = prdGroup.Key,
  21:                                                              Campaigns = prdGroup
  22:                                                          }
  23:                                           }
  24:                         };
  25:      });
  26:  }
by Hadi Eskandari
  February 19, 2010 @ 11:20pm
Tags:
Description:
Query of the day: How to convert flat structures to hierarchical

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate