Pasé mucho tiempo con este problema. Soy capaz de hacer sencilla Grupo Por consultas LINQ (en una sola propiedad) pero para múltiples campos que estoy un poco atascado ... Aquí es una muestra LINQPad de lo que quiero hacer:LINQ Group by con propiedades múltiples en 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()
El lFinal la lista tiene 6 elementos, quiero que lFinal2 tenga 4 elementos: 2010-6 y 2011-1 deben agruparse.
Gracias de antemano.
I also ha d implementar el GetHashCode() para que funcione. – Maher