ara ara - 4 months ago 5x
SQL Question

SQL - type is not valid

I have to use

Code of C#

public double price { get; set; }

Code of SQL

Select id, (0.0) AS price from Product

but during this code I got this error:

"ExceptionMessage":"The specified cast from a materialized
'System.Decimal' type to a nullable 'System.Double' type is not valid."

also I don't want to change code of c#, For solving I want to change code of Sql (not c#)


The (0.0) return a numeric type, which is mapped to Decimal. All you need is to cast into float, which is mapped to double, so :

SELECT id, cast(0.0 as float) AS price from Product

should do the trick.