Transform LINQ Dataset into a Matrix for export

Posted by Mad Halfling on Stack Overflow See other posts from Stack Overflow or by Mad Halfling
Published on 2010-06-01T12:18:56Z Indexed on 2010/06/01 12:23 UTC
Read the original article Hit count: 153

Filed under:
|

Hi folks, I've got a data table with columns in which include Item, Category and Value (and others, but those are the only relevant ones for this problem) that I access via LINQ in a C# ASP.Net MVC app. I want to transform these into a matrix and output that as a CSV file to pull into Excel as matrix with the items down the side, the categories across the top and the values in the row cells. However, I don't know how many, or what, categories there will be in this table, nor will there always be a record for each item/category combination. I've written this by looping round, getting my "master category" list, then looking again for each item, filling in either blank or Value, depending on whether the item/category record exists, but as there are currently 27000 records in the table, this isn't as fast as I'd like. Is there a slicker and faster way I can do this, maybe via LINQ (firing into a quicker SQL statement so the DB server can do the leg-work), or will any method essentially come back to what I am doing? Thx MH

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about LINQ