I have the code
myEntities db = new myEntities();
var query = from s in db.mytable select s;
if (!String.IsNullOrEmpty(str))
{
query = query.Where(p => p.total == str);
}
Here, the type of “total” is a string containing numbers and characters, e.g. “14x56xz”. I want to get the number part (e.g. 1456) from the “total” string and convert it to a decimal number, sometimes with the need to turn it into a negative number, making the code look like this:
query = query.Where(10 <= p => p.total <= 1000);
I have written a class to process it, but I don’t know how to invoke this processing method in Linq.
Just parse it in the lambda. For example:
Of course, if there’s any way you can improve your data model so that logically-numeric values are stored as numbers, that would be even better…
EDIT: I think you’ll have a hard time converting “14x56xz” to 1456 in LINQ to Entities. You may be able to do something at the database side to expose a computed column using conversions and regular expressions etc, but I’m not sure that you’d be able to express that in LINQ in a way which will be converted appropriately.