Linq到实体组的错误“尝试除以零”? [英] Linq to entity group by error "attemp to divide by zero"?

查看:234
本文介绍了Linq到实体组的错误“尝试除以零”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

let value2 = Grp.Count(x => x.Column1 <= 2 && x.Column2== "studentName") * 100 / Grp.Count(x => x.Column2== "studentName")









在本声明中,有时分隔符为空因此它传递NaN值我怎样才能将分隔符从0更换为1.



我尝试了什么:



let value2 = Grp.Count(x => x.Column1< = 2&& x.Column2 ==studentName)* 100 / Grp.Count(x = > x.Column2 ==studentName)







在本声明中有时候是分隔符是空的,所以它通过NaN值我怎么能r将分隔符从0到1放置。





In this Statement some times the divider is Null so it pass NaN value how can I replace the divider from 0 to 1.

What I have tried:

let value2 = Grp.Count(x => x.Column1 <= 2 && x.Column2== "studentName") * 100 / Grp.Count(x => x.Column2== "studentName")



In this Statement some times the divider is Null so it pass NaN value how can I replace the divider from 0 to 1.

推荐答案

使用解决方案1的链接或类似的扩展方法:
Either with an extension method like shown when following the link of solution 1 or like this:
Math.Max(Grp.Count(x => x.Column2== "studentName"), 1)


< a href =http://stackoverflow.com/questions/36053372/need-to-replace-0-with-1-in-linq?noredirect=1#comment59754375_36053372> c# - 在LINQ中需要用1替换0吗? - 堆栈溢出 [ ^ ]


这篇关于Linq到实体组的错误“尝试除以零”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆