Linq:如何使用system.linq.dynamic选择表达式?

时间:2017-08-01 17:42:42

标签: c#-4.0

我想用system.linq.dynamic构建动态查询 我如何将以下代码更改为system.linq.dynamic?

var qResult = 
    (from m in lstKPProductSales
    group m by new
    {
        m.ItemNo,
        m.ItemName,
    } 
    into d
    select new
    {
        d.Key.ItemNo,
        d.Key.ItemName,
        SumStore2001 = d.Where(c => c.StoreNo == "2001").Sum(c => c.ActualCostAmount),
        SumStore2002 = d.Where(c => c.StoreNo == "2002").Sum(c => c.ActualCostAmount),
        SumStore2003 = d.Where(c => c.StoreNo == "2003").Sum(c => c.ActualCostAmount),
        SumStore2004 = d.Where(c => c.StoreNo == "2004").Sum(c => c.ActualCostAmount),
        SumStore2005 = d.Where(c => c.StoreNo == "2005").Sum(c => c.ActualCostAmount),
        ///...
    }).ToList();

谢谢。

0 个答案:

没有答案