1

I have a list of data structured like this:

Field1 Field2 Field3 1 1 "abc" 1 1 "def" 1 2 "123" 1 2 "456" 

I want to be able to merge this data so I end up with a single record per Field1 & Field2 and with the Field3 data concatenated. So in the above case I would get:

Field1 Field2 Field3 1 1 "abcdef" 1 2 "123456" 

I would like to use linq/query expressions for this.

1 Answer 1

3
var query = from row in rows group row by new { row.Field1, row.Field2 } into g select new RowClass { Field1 = g.Key.Field1, Field2 = g.Key.Field2, Field3 = g.Aggregate( new StringBuilder(), (sb, grp_row) => sb.Append(grp_row.Field3)) .ToString() } 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I didn't realise you could group on multiple fields. I was trying to do nested grouping and just getting a mess.
Glad to help. I agree that it's not a very intuitive syntax.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.