开发者

Inform LINQ that a string represents a decimal and not a double value?

开发者 https://www.devze.com 2023-01-18 16:09 出处:网络
I am using the following snippet: var ws = string.Format(\" it.{0} >= {1} && it.{0} <= {2} \", column, min, max)

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?


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');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号