I’d like to order my list by a string converted into an int:
var orderedListOfRfidTags = uow.RfidTags.OrderBy(t => Convert.ToInt32(t.Number)).ToList();
but get: The method ‘ToInt32’ is not supported.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I am one of the developers of LightSpeed.
The LINQ provider in LightSpeed 3.11 RTM doesn’t support Convert.ToInt32. However we have now added support via a nightly release which is available for download now.
If you don’t want to use the nightly release, you can achieve the result you want by dropping down to the Query Objects API and invoking the SQL CAST function directly. This will look something like:
The reason for the rather verbose LiteralExpression for the cast type is that by default LightSpeed sends values to the database through parameters (to avoid SQL injection attacks). But for the CAST function the SQL engine needs to see
CAST(Number, INTEGER)rather thanCAST(Number, @p0)where p0 has the value “INTEGER”. So you have to use an EmitInline expression, which bypasses parameterisation, rather than the more natural string literal.Once again, though, the nightly release does support Convert.ToInt32 in LINQ so you only need to drop down to this level if you want to avoid taking a nightly build.