开发者

arithmetic operators in linq

do arithmetic operators not allowed in Linq. it giving error + can not applied to lambda expression. CostperResponse.Cost is of datatype decimal

        var costperrespone= from v in 开发者_如何转开发lstSale
                                 group v by v.ActionGroupName into g
                                 select new CostperResponse
                                 {
                                     ActionGroupName = g.Key,
                                     Cost = ((x => Convert.ToDecimal(x.ResponseROCount))) / ((x => Convert.ToDecimal(x.ResponseWPAmount)) + (x => Convert.ToDecimal(x.ResponseWPAmount)))
                                 };

the sqlserver query is

     select SUM((cast(isnull(response_ro_count,0) as decimal))/(cast(isnull(response_cp_amount,0)as decimal) + cast(isnull(response_wp_amount,0)as decimal))) , action_group_name from GM_Tempdata where cast(response_ro_count as decimal)>0 group by action_group_name


Cost = ((x => Convert.ToDecimal(x.ResponseROCount))) / ((x => Convert.ToDecimal(x.ResponseWPAmount)) + (x => Convert.ToDecimal(x.ResponseWPAmount))) 

"means"

Cost = (somefunc(x) {Convert.ToDecimal(x.ResponseROCount)))} 
/ (anotherFunc(x) { Convert.ToDecimal(x.ResponseWPAmount))} 
+ lastFunc(x) {Convert.ToDecimal(x.ResponseWPAmount)})) 

I'm not quite sure what you want to assign to Cost?

Possibly you meant something like

Cost = Convert.ToDecimal(v.ResponseROCount) / Convert.ToDecimal(v.ResponseWPAmount) + Convert.ToDecimal(v.ResponseWPAmount)

But since you've grouped, you are going to need to use an aggregate like Sum() etc?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜