0

I want to convert Row to Column, actually I can implement a Static row to column as below, but it only works if I know the row position beforehand, so does anyone know how to dynamically convert a Row to Column in Linq?

This is the below table

ItemCode  LOC001    LOC002   LOC003     
 AAA      10         11        12 
 BBB      13         31        14
 CCC      15         18        0

This is the Static Code:

var table=(from x in Mst_LocationItems

group x by x.ItemCode into gr
select new
       {
          ItemCode=gr.Key,
          LOC001 = gr.Where(x=>x.LocationID == "LOC001").Sum(x=>x.Reorder),
          LOC002 = gr.Where(x=>x.LocationID == "LOC002").Sum(x=>x.Reorder),
          LOC003 = gr.Where(x=>x.LocationID == "LOC003").Sum(x=>x.Reorder)
       }).ToList();

           table.Dump();

0 Answers0