错误:转换为值类型“Double”失败,因为实现值为null [英] Error :the cast to value type “Double” failed because the materialized value is null

查看:550
本文介绍了错误:转换为值类型“Double”失败,因为实现值为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个star_tbl。我想在我的网站上制作星球。我的鳕鱼:

i have a star_tbl . i wanna make starpart in my web site. my cod:

public int StarProduct(int id_Product)
{
  return Convert.ToInt32(db
    .tbl_satar_Product
    .Where(p => p.Id_Product == id_Product && p.star != null)
    .Average(s => s.star));
}





但是t显示此错误:



转换为值类型Double失败,因为具体化值为null。结果类型的通用参数或查询必须使用可空类型。





i也使用(s => s。 star ?? 0d)但它说:

operator'??'不能应用于'double'和'double'类型的操作数



but t shows this error :

the cast to value type "Double" failed because the materialized value is null. Either the result type 's generic parameter or the query must use a nullable type.


i used also (s=> s.star ?? 0d) but it says :
" operator '??' cannot be applied to operands of type 'double' and 'double' "

推荐答案

表格中有哪些值?您通过常规查询得到什么?
What values are in the table? What do you get with a regular query?


这篇关于错误:转换为值类型“Double”失败,因为实现值为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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