ara
ara

Reputation: 109

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#)

Upvotes: 1

Views: 643

Answers (1)

Martheen
Martheen

Reputation: 5580

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.

Upvotes: 1

Related Questions