0

So I have two DbSets worth of data, let's call them A and B. I want to join these together on two fields. I have that statement no problem. Once the two data sets are joined I get a distinct set or rows. Lastly, and this is the part I need help with, I need to find all rows where all fields are the same, except one column, and that column needs to be combined into a comma separate list.

Columns: Field1, Field2, Field3, Field4, Field5

Data Row 1: A, Apple, 1, 2, 3

Data Row 2: A, Orange, 1, 2, 3

Data Row 3: A, Cherry, 3, 2, 1

The data above is already joined and has distinct values. The code I need takes this data and outputs the following:

Columns: Field1, Field2, Field3, Field4, Field5

Data Row 1: A, [Apple, Orange], 1, 2, 3

Data Row 2: A, Cherry, 3, 2, 1

When the data in Field1, 3, 4, and 5 are the same I need to join all the items in Field2 into a comma separated string or List, ideally. I should also note that currently the data rows are an anonymous type.

Any ideas?

ddelella
  • 67
  • 1
  • 7
  • https://stackoverflow.com/questions/799446 – Robert Harvey Jul 30 '20 at 17:01
  • Use `GroupBy` then `Select`. Please show your code - are you using LINQ Fluent/Lambda Syntax or Query Syntax? – NetMage Jul 30 '20 at 17:58
  • @NetMage I am using LINQ Lambda syntax. I think I found a solution at: https://forums.asp.net/t/2067132.aspx?How+to+Concatenate+multiple+rows+into+a+single+row+in+LINQ. I did not post the code because the actual wording is proprietary and I did not have time to work up a sample. If the code I found works I will post the working solution. – ddelella Jul 30 '20 at 18:22

0 Answers0