c# - Linq GroupBy Projection with Multiple Groups -


I have a table in DB that stores the data value and a two tiered label.

  data {int id, string label, string section, double value}  

An example entry to illustrate my problem:

{"Sports", "Football", "Sport", "Food", "", 34} {"Food", "Pizza", 56} {"Sports", "Baseball", 33} , 44} {"Food", "Donuts", 19}

I want to be able to print such values:

  Sports | 12 baseball | 33 football 44 food | 34 Pizza | 56 donuts | 1 9  

This code I have is completed by my 50%:

  var first = (d to db.Data where d Select .ID = PARAM d); Var line = First Group by (x = & gt; x.Label); Leading (var k) in line {Console.Write (k.Key + "\ t |"); Forchach (various Jammu in Kashmir) {console. White (J. Data); } Console. Type ("\ n"); }  

But it just prints:

  Game | 12 games | 33 games | 44 food | 34 food 56 food | 19  

I understand that, I do not know how to reach . k.key to <

How can I use to get my desired output?

I had to do this work:

var row = first.GroupBy (x => new {X.Label, x.Section});

  foreach (var k) in line {Console.Write (k.Key.Section == faucet} k.Key.Section == ""? K.Key.Label: k. Key.Section); ...}  

New question:

How can I find out the edge of "sports" / "food" I want to insert a divider (------------);

should print

 games | 12 baseball | 33 football 44 ------------- Food | 34 Pizza | 56 donuts | 19 ------------- 

Comments