Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select specific columns for Linq group by

I have a nested ListView. Kinda like this one:
http://mattberseth.com/blog/2008/01/building_a_grouping_grid_with.html

And the following Linq query:

var query = (from c in context.customer_order
             where c.id > 8000
             group c by c.person_id into cgroup
             select new { cgroup.Key, Orders = cgroup });

I only want to load a few specific columns into the cgroup item. Just like you normally do with the "select" statement in SQL. Is that possible? I have a blob in the table and it takes ages to load if it is included.

like image 302
Remy Avatar asked Feb 02 '11 08:02

Remy


2 Answers

var query = (from c in context.customer_order
             where c.id > 8000
             group c by c.person_id into cgroup
             select new { cgroup.Key, Orders =
                    from item in cgroup
                    select new { item.Foo, item.Bar }
             });
like image 79
Marc Gravell Avatar answered Nov 05 '22 01:11

Marc Gravell


var query = (from c in context.customer_order
             where c.id > 8000
             group c.Column by c.person_id into cgroup
             select new { cgroup.Key, Orders = cgroup });

Or if you need a few column s:

var query = (from c in context.customer_order
             where c.id > 8000
             group new { c.Column1, c.Column2 } by c.person_id into cgroup
             select new { cgroup.Key, Orders = cgroup });
like image 22
leppie Avatar answered Nov 05 '22 00:11

leppie