Problem VB.NET LINQ Group joining -


ok know there lot of posts on have trying solve few hours , brain off.

here thing

i have list of object 3 properties (quantity, service, name)

i want have names , services in list (kinda cross join) , grouped quantity of row corresponding. not clear guess

quantity service name
3 srv2 bob
4 srv2 paul
2 srv1 paul
1 srv2 nick

i want output
services , names , corresponding quantities (0 if none)

srv1 paul 2
srv1 bob 0
srv1 nick 0
srv2 paul 4
srv2 bob 3
srv2 nick 1

here got far, dont expected results , acutally there pretty easy way of achieving want... little welcome...

thanks

    dim services = (from in interventions select new {.service = a.service}).distinct()     dim months = (from b in interventions select new {.month = b.dateheureintervention.month}).distinct()      'dim query = (from s in services _     '             m in months _     '             in interventions.where(function(x) x.service = s.service , x.dateheureintervention.month = m.month).defaultifempty(new intervention()) _     '             select new chartitem {.service = s.service, _     '                                        .name = monthname(m.month), _     '                                        .quantite = i.quantite}).tolist()      'return (from q in query _     '       group srv = q.service, n = q.name group _     '       select new chartitem {.name = n, _     '                                  .service = srv, _     '                                  .quantite = group.sum(function(i) i.quantite)}).tolist()       dim q = (from in interventions _             group join s in services on s.service equals i.service si = _             group join m in months on m.month equals i.dateheureintervention.month _             x in si.defaultifempty() _             group m = i.dateheureintervention.month, srv = i.service group _             select new chartitem {.service = srv, _                                        .name = monthname(m), _                                        .quantite = group.sum(function(y) y.i.quantite)}).tolist()      return q 

i got here result, there surely better way, anyhow, works

    dim months list(of integer) = (from b in interventions select b.dateheureintervention.month).distinct().tolist()     dim services list(of string) = (from c in interventions select c.service).distinct().tolist()      dim q = (from s in services _              m in months _              select new chartitem {.name = monthname(m), _                                         .service = s, _                                         .quantite = (from in accesdonneeshelper.getinterventionsdetails() _                                                      i.service = s , i.dateheureintervention.month = m _                                                      select i.quantite).sum()}).tolist() 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -