I have a LINQ query which returns a set of rows. The structure is:
NAME, col1, col2, col3, col4
name1 1 null null null
name1 null 1 null null
name1 null null 1 1
As a result I want to have one row containing
name1 1 1 1 1
So I want to group those results by name and merge (sum?) the other columns so if I have not null in one of the rows in a column - I will receive anything except null.
Thanks for help!
yields
and
yields
EDIT: In response to your clarification...
I guess you'll be able to take it from here then. If all you want to do is find out whether there is a column within the group, then the
Any
operator like in Bruno's answer is the way to go.Aggregate
is only necessary if you're trying to actually visit all the values in order to do something more complex like summing them (although as Jon alluded to,Sum
handles that specific case).In short, what you want is grouping like in both the answer, and then within the group you either use
Aggregate
to merge row by row or multipleAny
on the results of theGroupBy
depending on which is clearer in your context (or more efficient if you have a large set of data within each group)