1

I have 1 very basic table which I need to query in order to get the amount (count) of rooms in each building code using a LinQ query.

So far i have this:

var myQuery = 
    from s in Locations 
    group  s.Room by s.BldgCode into t
    select t.Count();

        myQuery.Dump();

with this output

Query (3 items)
2
4
7

How can I include the Building code details so I have an output like this:

BldgCode    NoRooms (3 items)
   A           2
   B           4
   C           7
Neel
  • 11,625
  • 3
  • 43
  • 61

1 Answers1

0
foreach(var line in data.GroupBy(info => info.Room )
                        .Select(group => new { 
                             BldgCode = group.Key, 
                             NoRooms = group.Count() 
                        })
                        {
     Console.WriteLine("{0} {1}", line.BldgCode , line.NoRooms );
}
Neel
  • 11,625
  • 3
  • 43
  • 61
  • Thanks, that works however is there a way to display the table neatly with headers using LINQPad4 other than the WriteLine function... – user3659328 May 21 '14 at 06:14
  • u mean you want to display table in console? – Neel May 21 '14 at 06:19
  • yes, sorry I know its basic but I just cant seem to get it right – user3659328 May 21 '14 at 06:21
  • don't say sorry even I am a learner :) this links might be useful for u http://stackoverflow.com/questions/856845/how-to-best-way-to-draw-table-in-console-app-c, http://tech.pro/tutorial/1267/displaying-tables-in-a-c-console – Neel May 21 '14 at 06:23