Select specific columns for the Linq group.

I have a nested ListView. How it looks like:
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 element. Just like you usually do with the select statement in SQL. Is it possible? I have a blob in a table, and it takes age to load it if it is enabled.

+3
source share
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 }
             });
+7
source
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 multiple s columns :

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 });
+2
source

Source: https://habr.com/ru/post/1789435/


All Articles