Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I use a string.CompareTo method in Lambda expression

Expression<Func<T, bool>> filter = s => s.SourceBatch.CompareTo(FromValue)>0;


this throws an exception:

Additional information: variable 's' of type '{namespace}.TransactionList' referenced from scope '', but it is not defined

I don't know how to resolve this

I need to filter some records of string type from DB.
One of Db filtering method's input parameters is the filter, im trying to build

Any help please!!

What I have tried:

When I use some simple filter like

Expression<Func<T, bool>> filter = s => s. == FromValue;


It works, but the problem is that CompareTo method is not recognized/not supported
Posted
Comments
Richard Deeming 8-Feb-17 10:22am    
Based on the error message, I suspect the problem is nothing to do with the CompareTo call.

Instead, it sounds like you're combining multiple filter expressions, but you've forgotten to rewrite them to replace their parameters with the parameter for the final expression.
Gurgen Chlingaryan 3-Mar-17 9:18am    
I've solved the problem, but it was not related to CompareTo method.
I used a third party developed framework with its own filtering logic, so standard lambda expressions didn't work for him...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900