This project has moved and is read-only. For the latest updates, please go here.

String comparing on greater / less than value

Jan 20, 2016 at 3:10 AM
We'd like to compare strings as per the following query:

x => x["DocDate"] >= from && x["DocDate"] <= to

from / to are strings, so we are getting "Operator '>=' cannot be applied to operands of type 'object' and 'string'"

The following one goes the sa,me way:

x => (string)x["DocDate"] >= from && (string)x["DocDate"] <= to

Is there any way to overcome that?
Jan 20, 2016 at 3:13 AM
Alright, will the following be the right assumption?

x => (DataTypes.Text)x["DocDate"] >= (DataTypes.Text)from && (DataTypes.Text)x["DocDate"] <= (DataTypes.Text)to
Jan 20, 2016 at 9:15 AM
Hi Anton,
in this case there won't be compilation error, but this expression is not valid currently in Camlex, and I'm not sure that it should be valid if even compiler doesn't allow it. I understand that in real life there may be situations when you need to compare strings in lexicographical order, but it should be done carefully, because often it leads to unpredictable errors especially when you compare strings which represent dates. Can't you use normal DateTime type for the filter?
Jan 21, 2016 at 1:22 AM
Edited Jan 21, 2016 at 1:23 AM
Understand that.
lexicographical order ... specially when you compare strings which represent dates
Exactly the case, pre-1900 dates case :)

The following one does the job:
x => x["DocDate"] >= (DataTypes.Text)from && x["DocDate"] <= (DataTypes.Text)to

Thanks for the tips!