Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Linq中行到列的动态转换_C#_.net_Linq - Fatal编程技术网

C# 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 =

我想将行转换为列,实际上我可以实现静态的行到列,如下所示,但它只有在我事先知道行的位置时才起作用,所以有人知道如何在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 == "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();