我在這個問題上花了很多時間。我能夠做簡單的集團通過LINQ查詢(在一個屬性),但多個字段我有點卡住... 這裏是什麼,我想做一個LINQPad樣本:LINQ Group by with VB.Net中的多個屬性
dim lFinal={new with {.Year=2010, .Month=6, .Value1=0, .Value2=0},
new with {.Year=2010, .Month=6, .Value1=2, .Value2=1},
new with {.Year=2010, .Month=7, .Value1=3, .Value2=4},
new with {.Year=2010, .Month=8, .Value1=0, .Value2=1},
new with {.Year=2011, .Month=1, .Value1=2, .Value2=2},
new with {.Year=2011, .Month=1, .Value1=0, .Value2=0}}
Dim lFinal2 = From el In lFinal
Group el By Key = new with {el.Year,el.Month}
Into Group
Select New With {.Year = Key.Year, .Month=Key.Month, .Value1 = Group.Sum(Function(x) x.Value1), .Value2 = Group.Sum(Function(x) x.Value2)}
lFinal.Dump()
lFinal2.Dump()
的lFinal目錄中有6個項目,我想讓lFinal2有4個項目:2010-6和2011-1應該分組。
在此先感謝。
我也ha d來實現GetHashCode()以使其工作。 – Maher 2013-01-02 12:45:39