Say i have a DataTable object with data from the database, and I need to reorganize it. I think (according to my research) LINQ would be an elegant (but is it fast?) way to do so. The question is how.
The data comes from the database in the following format
ORDER SAMPLE METHOD
1234 1 ASH-10
1234 1 ASH-11
1234 1 ASH-12
1234 2 ASH-10
1234 2 ASh-12
1234 5 ASH-10
1235 1 BSH-10
1235 1 BSH-11
1235 1 BSH-12
I need it to be reshuffled as
ORDER SAMPLE ASH-10 ASH-11 ASH-12 BSH-10 BSH-11 BSH-12
1234 1 Y Y Y N N N
1234 2 Y N Y N N N
1234 5 Y N N N N N
1235 1 N N N N Y Y
As you can see the method columns will be dynamic. I could, of course, loop through the data using the old fashioned loop, but it seems like LINQ would be a better and faster way to go about it. Correct me if I am wrong.
The DataTable is great for retrieving data from the database into your application, but once you have the data you are usually better off converting it into custom objects.
Your preliminary design might look like this: