C# Linq中行到列的动态转换
我想将行转换为列,实际上我可以实现静态的行到列,如下所示,但它只有在我事先知道行的位置时才起作用,所以有人知道如何在Linq中动态地将行转换为列吗 这是 这是静态代码:C# Linq中行到列的动态转换,c#,.net,linq,C#,.net,Linq,我想将行转换为列,实际上我可以实现静态的行到列,如下所示,但它只有在我事先知道行的位置时才起作用,所以有人知道如何在Linq中动态地将行转换为列吗 这是 这是静态代码: 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 =
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();
你能给我更多关于我的编码的细节吗?你能提供更多关于“动态”对你意味着什么的细节吗?
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();