我想将行转换为列,实际上我可以如下实现静态行至列,但是只有在我事先知道行位置的情况下它才能起作用,所以有人知道如何在Linq中将行动态转换为列吗?
ItemCode LOC001 LOC002 LOC003
AAA 10 11 12
BBB 13 31 14
CCC 15 18 0
这是静态代码:
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();