Using LINQ, I get the following error...
Operator '>' incompatible with operand types 'Decimal?' and 'String'
...in WHERE query Price > @Price
Is the mapping wrong? I map the Price column of type MONEY to DECIMAL. According to the following table on msdn it should be fine.
What could go wrong? I found a solution on Raj Kaimal's blog which fixed my problem :
According to the Dynamic Expression API,
a flavor of which is used by the LinqDataSource internally, we can
perform explicit conversions using the syntax type(expr) where type is
a type name optionally followed by ? and expr is an expression. The
expression language defines the following primitive types:
Object Boolean Char String SByte Byte
Int16 UInt16 Int32 UInt32 Int64 UInt64
Decimal Single Double DateTime TimeSpan Guid
The primitive types correspond to the similarly named types in the
System namespace of the .NET Framework Base Class Library. You can also
use the nullable form of a value type by writing a ? after the type
name (ex: Where="Foo = Int32?(@Foo)").
Therefore, we can rewrite our where clause like so which gets rid of the exception.
|
d367acad-24a0-4ad1-88cb-0d2dcb126bb6|0|.0