How To Create Pivot Table From Datatable Using Linq?

Hi Guys,

I have a datatable like this;

name    |   color of name
----------------------
x       |   red
y       |   blue
z       |   yellow
x       |   yellow
y       |   red

I want to get datatable’s pivot table. But i couldnot do it. I am not good at linq queries? How can i change it like this;

name    |   red     |   blue    |   yellow  | total
-------------------------------------------------------
x       |   1       |   0       |   1       |   2
y       |   1       |   1       |   0       |   2
z       |   0       |   0       |   1       |   1

I want this work flow
can u please send me.

1 Like

i use BalaReVa’s Datatable library. You can install this package from “Manage Packages” menu