rogerzebra
Technical User
Hi All,
I clearly need someone to help me with a piece of code that I found online that I have hard to understand and apply it to my project. I'm totally new to C# and LINQ and I would really appreciate if someone could help me out due to the short deadline. So, I'm trying to read in the data from the EDM(Entity framework)to show the column records as rows like transpose a table it's just this has to be read straight from the database. Thanks for your help in advance it is really appreciated.
from
ID Date Amount
1 2/1/2012 100
2 2/2/2012 200
3 2/3/2010 300
to...
ID 1 2 3
Date 2/1/2012 2/2/2012 2/3/2012
Amount 100 200 300
I clearly need someone to help me with a piece of code that I found online that I have hard to understand and apply it to my project. I'm totally new to C# and LINQ and I would really appreciate if someone could help me out due to the short deadline. So, I'm trying to read in the data from the EDM(Entity framework)to show the column records as rows like transpose a table it's just this has to be read straight from the database. Thanks for your help in advance it is really appreciated.
from
ID Date Amount
1 2/1/2012 100
2 2/2/2012 200
3 2/3/2010 300
to...
ID 1 2 3
Date 2/1/2012 2/2/2012 2/3/2012
Amount 100 200 300
Code:
public static IEnumerable<IEnumerable<T>> Transpose<T>(this IEnumerable<IEnumerable<T>> source)
{
return from row in source
from col in row.Select((x, i) => new KeyValuePair<int, T>(i, x))
group col.Value by col.Key into c select c as IEnumerable<T>;
}