LINQ nested groupby issue RRS feed

  • Question

  • I have a view from SQL server which returns the following data:

    GroupLvl1ID, GroupLvl1Desc, GroupLvl2ID, GroupLvl2Desc, GroupLvl3ID, GroupLvl3Desc..e.g.
    1, "Group1Desc", 1, "Group2Desc", 1, "Group3Desc"
    1, "Group1Desc", 1, "Group2Desc", 2, "Group3Desc2"
    1, "Group1Desc", 2, "Group2Desc2", 3, "Group3Desc3"
    1, "Group1Desc", 2, "Group2Desc3", 4, "Group3Desc4"
    2, "Group1Desc2"........(and so on)


    I am trying to use nested Linq statement to group the result, and then loop each level to get the descriptions in proper hierarchy..... ie.

    for each (group1 in GroupLvl1){
          for each (group2 in GroupLvl2){
                for each (group 3 in GroupLvl3){
                        ...display group3 descriptions 

    I tried to use nested group statement in linq but I am kind of stuck with the syntax..can anyone give me an example on how to achieve a nested linq group using the data? 

    Thanks in advance.


    --- WML ---
    Monday, January 30, 2012 6:36 AM