I have a simple LINQ-to-Entities query as below:
var BillingNumbers = from o in dbcontext.Orders
where SqlFunctions.IsNumeric(o.BillingNumber) == 1
select o.BillingNumber;
This query works most of the time. Recently, however, I encountered a situation where the BillingNumber was indeed numeric, but had some trailing spaces. This query completely missed those values.
If SqlFunctions.IsNumeric() can’t ignore the trailing spaces, what are the alternatives?
.Net 4/EF4/VS2010
You can do
It translates to
Be aware of the fact that this way of querying is not sargable, so if you can narrow down your orders in any other way before this comparison, make sure you do it!