Inside my SQL table, i have a version column with string
datatype which contains typical version values like '1.0.0' and '2.0.2' and so on.
I want to write a query which retrieve all the records with the version lower/greater than the specified version.
For example, suppose my table is like this:
====MY TABLE====
version column2 column3 , ....
_________________________________________________
2.0.6 ... ... ...
2.0.5 ... ... ...
2.0.4 ... ... ...
2.0.3 ... ... ...
Now i want to retrieve all the records with version
lower and equal to 2.0.5
My main issue is that the input (2.0.5 in this case) and the version
column values are both strings. So they cannot be compared normally.
I've tried :
from o in MyTable.Where(w=> float.Parse(w.version) <= float.Parse(inputVersion) )
/* Other codes ommited for clarity */
But obviously it throws an exception because 2.0.3
is not a float.
There is a method that compares two version strings but i cannot use it inside a Linq2Sql query since it throws an exception saying
"Method X has no supported translation to SQL."
Also i've tried:
from o in MyTable.Where(w=> Version.Parse(w.version) <= Version.Parse(inputVersion) )
/* Other codes ommited for clarity */
But it throws the same exception as well.
So my question would be how can i compare these values inside a linq to sql query?