Quantcast
Channel: Pivot table in c# entity framework
Viewing all articles
Browse latest Browse all 6

Pivot table in c# entity framework

$
0
0

Maybe a bit too late but better ever than never.

This dataset (actually any enumerable source, not only Entity Framework collections) can be easily pivoted with NReco PivotData C# library http://www.nrecosite.com/pivot_data_library_net.aspx (note that core NReco.PivotData.dll is a free component) in the following way:

var pvtData = new PivotData(
  new[] {"ISO Code", "description", "Year"}, // list of dimensions for grouping
  new SumAggregatorFactory() );
pvtData.ProcessData( theCollection ); // use appropriate overload depending on the input source

var pvtTbl = new PivotTable(
   new[] {"ISO Code", "description"},   //rows
   new[] {"Year"}, // columns
   pvtData);
   
// iterate through pvtTbl.RowKeys and pvtTbl.ColumnKeys to get pivot table values and build DataTable

This way is much easier than writing custom C# code each time for specific dataset!

In case of any questions feel free to contact me (I'm an author of PivotData library).


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>