Here is the solution I came up with. Note that this is close to the solution proposed by @OdeToCode (but in VB syntax), with one significant difference:
Dim temp = _ (From t In context.MyTable _ Group t.f1, t.f2, t.f3 By t.title Into g = Group _ Select title, g).ToList Dim results = _ From t In temp _ Select t.title, _ f1_count = tgCount(Function(x) If(x.f1, False)), _ f2_count = tgCount(Function(x) If(x.f2, False)), _ f3_count = tgCount(Function(x) If(x.f3, False))
The first request does the grouping, but ToList receives the grouped data as it is from the server. Eliminating the count here causes the resulting SQL query to create a sub-SELECT for each count. I am doing the count in the second query locally.
This works since I know that the first query will return a manageable number of rows. If he were to return millions of rows, I probably would have to go in the other direction.
gfrizzle
source share