Click here to Skip to main content
15,887,300 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a star_tbl . i wanna make starpart in my web site. my cod:
C#
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));
}


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' "
Posted

1 solution

What values are in the table? What do you get with a regular query?
 
Share this answer
 
Comments
Ron Beyer 17-Aug-13 13:32pm    
Should probably be a "question or comment", not a solution. (I'm not the one that downvoted)
Member 8454063 17-Aug-13 13:44pm    
in table i have username(FK) , id_Product(FK) ,Star , IP

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900