Trying to pivot dynamic data using LINQ or LAMBDA in C#/MVC4 and have pretty much come to the conclusion that its very difficult to do..
This is basically what I want to do:

I have been able to get this to work with known column names using this example: http://geekswithblogs.net/malisancube/archive/2009/04/21/using-lambda-or-linq-for-pivot-tables.aspx
But I cant find any examples for doing this with dynamic columns.
By dynamic columns I mean that there could be a new row with a different Name and FieldType that has not been in the table before at any time that also needs to be turned into a column.. any pointers?.
I don’t know
LINQso I will give you a version that can be used in a SQL Server stored procedure. This type of data transformation is known as aPIVOT. Since you are using SQL Server 2008+, you can use the function.If you know the values that you want to transform, then you can hard-code the values:
See SQL Fiddle with Demo
Then if you have an unknown number of values, you can implement dynamic SQL:
See SQL Fiddle with Demo
Both return the results: