[VB.net] 使用Linq作資料分組計數加總

使用SQL非常容易,但用Linq就不是很友善了

使用Linq

Dim groups = 
    From j In MyTable
    Group By x = New With {Key .var1 = j.var1, Key .var2 = j.var2, Key .var3 = j.var3} Into g = Group
    Select New With {
        .var1 = x.var1,
        .var2 = x.var2,
        .var3 = x.var3,
        .quantity = g.Sum(Function(r) r.qty),
        .count = g.Count()
    }