LINQ to SQL version of GROUP BY WITH ROLLUP

后端 未结 4 494
予麋鹿
予麋鹿 2020-12-31 17:56

I\'m trying to rewrite some old SQL into LINQ to SQL. I have a sproc with a GROUP BY WITH ROLLUP but I\'m not sure what the LINQ equivalent would be. LINQ has a GroupBy bu

4条回答
  •  时光说笑
    2020-12-31 18:41

    Quite interesting solution is provided here

    https://blogs.msdn.microsoft.com/mitsu/2007/12/21/playing-with-linq-grouping-groupbymany/

    It describes how to perform groupbby by several properties. I.e:

    var result = customers.GroupByMany(c => c.Country, c => c.City);
    

    As result you would get hierarchical structure that can be simply converted to flat list.

提交回复
热议问题