views:

20

answers:

1

I am using the following snippet:

var ws = string.Format(" it.{0} >= {1} && it.{0} <= {2} ", column, min, max)

as part of query. “it” represents the record at hand. I then use this string in a

Var result = AllRecords
        .Where(ws)
        .OrderBy(it.ProductName);

The problem I have, is that when the column type is Decimal the LINQ interprets the passed in string as double and fails by saying the types double and decimal are incompatible:

The argument types 'Edm.Decimal' and 'Edm.Double' are incompatible for this operation. Near greater than or equals expression, line 8, column 12. where: ( it.Cost >= 70.5 && it.Cost <= 100 ) orderby: it.ProductName

how can I ensure that LINQ will realize the string must be interpreted as decimal and not double?

+1  A: 

Found it: I need to suffix the string that contains a double with 'M', in my case:

var ws = string.Format(" it.{0} >= {1} && it.{0} <= {2} ", column, min+'M', max+'M');
furd