how to group by over anonymous type with vb.net linq to object
Posted
by smoothdeveloper
on Stack Overflow
See other posts from Stack Overflow
or by smoothdeveloper
Published on 2010-02-25T18:12:51Z
Indexed on
2010/03/14
2:55 UTC
Read the original article
Hit count: 548
I'm trying to write a linq to object query in vb.net, here is the c# version of what I'm trying to achieve (I'm running this in linqpad):
void Main()
{
var items = GetArray(
new {a="a",b="a",c=1}
, new {a="a",b="a",c=2}
, new {a="a",b="b",c=1}
);
(
from i in items
group i by new {i.a, i.b} into g
let p = new{ k = g, v = g.Sum((i)=>i.c)}
where p.v > 1
select p
).Dump();
}
// because vb.net doesn't support anonymous type array initializer, it will ease the translation
T[] GetArray<T>(params T[] values){
return values;
}
I'm having hard time with either the group by syntax which is not the same (vb require 'identifier = expression' at some places, as well as with the summing functor with 'expression required' )
Thanks so much for your help!
© Stack Overflow or respective owner