Skip navigation links

MySQL Forums :: C#, Mono, .Net :: Comparing a VARCHAR as if it were numeric


Advanced Search

Comparing a VARCHAR as if it were numeric
Posted by: Walt Stoneburner ()
Date: February 25, 2010 10:14AM

I have a table with a column of type varchar where the majority of rows have numerical looking values, that is, each string contains nothing but the digits 0 through 9.

SQL like this works perfectly, implicitly type-casting varchar to a numeric for comparisons:
SELECT * FROM t WHERE n >= 200 AND n <= 500;

However, I'm stuck using C#/.NET's LINQ to Entity Framework and am getting an error message that "LINQ to Entities does not recognize the method 'Int64 Parse(System string) method, and this method cannot be translated into a store expression."

var results = from n in context.t
let n_asLong = long.Parse(n)
where ( n != null && n_asLong >= 200 && n_asLong <= 500 )
select n_asLong;


What's the right way to encode the type-change into the comparison?

Thanks,
Walt Stoneburner
wls@wwco.com

Options: ReplyQuote


Subject Written By Posted
Comparing a VARCHAR as if it were numeric Walt Stoneburner 02/25/2010 10:14AM


Sorry, you can't reply to this topic. It has been closed.