选择Linq group by的特定列

时间:2011-02-02 08:22:10

标签: .net linq listview group-by

我有一个嵌套的ListView。有点像这样:
http://mattberseth.com/blog/2008/01/building_a_grouping_grid_with.html

以下Linq查询:

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 });

我只想在cgroup项中加载一些特定的列。 就像通常使用SQL中的“select”语句一样。 那可能吗?我在表中有一个blob,如果包含它,它需要很长时间才能加载。

2 个答案:

答案 0 :(得分:7)

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 }
             });

答案 1 :(得分:2)

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 });

或者,如果您需要几列 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 });