Linq and group by clause -


i curious x in a linq group clause: group x by ...

the x can replaced 1:

       var query = box in c.boxes                     join item in c.items on box equals item.box                     group 1 new { boxid = box.boxid, item.itemtype.itemtypeid } g                     select new {  g.key.boxid, g.key.itemtypeid, count = g.count() }; 

does have sample x (or wathever local variable chose in group ) of value?

i mean

var query2 =  box in c.boxes                               group box box.boxid q                               select q.key; 

can replaced by

var query2 =  box in c.boxes                               group 1 box.boxid q                               select q.key; 

in group x by... x gets aggregated.

so write

var childrenbyage = child in class                     group getname(child) child.age; 

this gives grouping containing names of children each age.

here simple example can test difference easily:

    static void main(string[] args)     {         var grouping = c in "hello world!"                        group c  c;  // replace 'group c by' 'group 1 by'                                        // , compare results           foreach (var group in grouping)         {             console.write("key:  {0} values :", group.key);             foreach (var value in group)                 console.write(" {0}", value);              console.writeline();         }          console.readkey();      } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -