Group by with multiple columns using lambda

后端 未结 5 821
一个人的身影
一个人的身影 2020-12-02 16:09

How can I group by with multiple columns using lambda?

I saw examples of how to do it using linq to entities, but I am looking for lambda form.

5条回答
  •  攒了一身酷
    2020-12-02 16:59

    if your table is like this

    rowId     col1    col2    col3    col4
     1          a       e       12       2
     2          b       f       42       5
     3          a       e       32       2
     4          b       f       44       5
    
    
    var grouped = myTable.AsEnumerable().GroupBy(r=> new {pp1 =  r.Field("col1"), pp2 = r.Field("col2")});
    

提交回复
热议问题