将查询转换为Lambda表达式



如何为以下SQL查询编写lambda表达式:

Sales_This_Month = SUM(CASE 
                         WHEN Trxn_Type_Code IN ('S','PS','RTN','GS','GR') 
                              AND YEAR(Trxn_Date) = YEAR(GETDATE()) 
                           THEN Amount 
                           ELSE 0 
                       END)

您可以在数据源对象上应用以下Lambda表达式。这里salesData是您的数据源对象。了解更多关于这里的信息。

 var result = salesData.Where(x=> (IList<string>)new [] { "S","PS","RTN","GS","GR" }).Contains(x.Trxn_Type) &&  Trxn_Date.Year == DateTime.Now.Year).Sum(x=>x.Amount);

尝试以下操作:

var result = salesData.Select(d => d.Where(x=> (IList<string>)new [] { "S","PS","RTN","GS","GR" })
.Contains(x.Trxn_Type) &&  Trxn_Date.Year == DateTime.Now.Year)).Count!=0?
d.Where(x=> (IList<string>)new [] { "S","PS","RTN","GS","GR" })
.Contains(x.Trxn_Type) &&  Trxn_Date.Year == DateTime.Now.Year).Sum(x=>x.Amount) : 0);

相关内容

  • 没有找到相关文章

最新更新