LinQ如何在SUM方法中进行乘法运算

时间:2009-10-26 14:15:41

标签: linq sum

已解决:IstBestellwert = grouped.Sum(o =>(double)o.SollMenge *(double)o.Preis)正常工作

我的SQL语句

 SELECT        ABId, SUM(Preis * IstMenge) AS IstBestellwert, SUM(Preis * SollMenge) AS SollBestellwert
    FROM            vChainStoreOrderingDetails
    GROUP BY ABId, FilialId
    HAVING  

  (ABId = 10) AND (FilialId IN (8, 140))

我在linq中的尝试

from csod in db.vChainStoreOrderingDetails
                                  where csod.Lieferdatum == lieferdatum && csod.ABId == ab.Id
                                  && filialen.Select(o => o.FilialId).Contains(csod.FilialId)
                                  group csod by new
                                  {
                                      csod.ABId
                                  } into grouped
                                  select new
                                  {
                                     test =grouped.Sum(o=> new {  test =((double) o.Preis * (double)o.SollMenge)})
                                  });

但选择部分不起作用。如何在groups.Sum()中进行乘法运算 所以我总结了多重值

1 个答案:

答案 0 :(得分:2)

IstBestellwert = grouped.Sum(o =>(double)o.SollMenge *(double)o.Preis)

好的,这种看起来像是在努力询问